@ledgerhq/coin-evm 7.0.0 → 9.0.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/.oxlintrc.json +1 -1
- package/CHANGELOG.md +62 -0
- package/docs/getBlock-internal-txs-schema.md +1 -1
- package/docs/network/node/index.md +3 -1
- package/lib/adapters/blockOperations.d.ts +4 -3
- package/lib/adapters/blockOperations.d.ts.map +1 -1
- package/lib/adapters/blockOperations.js +17 -17
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/adapters/etherscan.d.ts +7 -6
- package/lib/adapters/etherscan.d.ts.map +1 -1
- package/lib/adapters/etherscan.js +19 -19
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/adapters/ledger.d.ts +6 -5
- package/lib/adapters/ledger.d.ts.map +1 -1
- package/lib/adapters/ledger.js +15 -15
- package/lib/adapters/ledger.js.map +1 -1
- 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/config.d.ts +0 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/logic/common.js +1 -1
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js +3 -3
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +22 -23
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getStakes.d.ts.map +1 -1
- package/lib/logic/getStakes.js +2 -2
- package/lib/logic/getStakes.js.map +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts +3 -2
- package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js +13 -10
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/listOperations.js +1 -1
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic-public/utils.d.ts +3 -2
- package/lib/logic-public/utils.d.ts.map +1 -1
- package/lib/logic-public/utils.js +7 -6
- package/lib/logic-public/utils.js.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +3 -2
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js +13 -12
- 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 +11 -11
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/types.d.ts +2 -2
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/explorer/types.js.map +1 -1
- package/lib/network/node/explorerProxy.js +3 -3
- package/lib/network/node/explorerProxy.js.map +1 -1
- package/lib/network/node/index.d.ts.map +1 -1
- package/lib/network/node/index.js +2 -2
- package/lib/network/node/index.js.map +1 -1
- package/lib/network/node/ledger.d.ts +2 -1
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js +9 -10
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +3 -2
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +37 -29
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/staking/contracts.js +2 -2
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/fetchers.d.ts.map +1 -1
- package/lib/staking/fetchers.js +7 -7
- package/lib/staking/fetchers.js.map +1 -1
- package/lib/staking/prepareIntents.d.ts +2 -1
- package/lib/staking/prepareIntents.d.ts.map +1 -1
- package/lib/staking/prepareIntents.js +4 -4
- package/lib/staking/prepareIntents.js.map +1 -1
- package/lib/staking/redelegations.d.ts +5 -4
- package/lib/staking/redelegations.d.ts.map +1 -1
- package/lib/staking/redelegations.js +13 -14
- package/lib/staking/redelegations.js.map +1 -1
- package/lib/staking/rewards.d.ts +2 -1
- package/lib/staking/rewards.d.ts.map +1 -1
- package/lib/staking/rewards.js +4 -5
- package/lib/staking/rewards.js.map +1 -1
- package/lib/staking/rewardsFromReceipt.d.ts +2 -1
- package/lib/staking/rewardsFromReceipt.d.ts.map +1 -1
- package/lib/staking/rewardsFromReceipt.js +2 -3
- package/lib/staking/rewardsFromReceipt.js.map +1 -1
- package/lib/staking/unbondings.d.ts +2 -1
- package/lib/staking/unbondings.d.ts.map +1 -1
- package/lib/staking/unbondings.js +4 -5
- package/lib/staking/unbondings.js.map +1 -1
- package/lib/staking/validators/index.d.ts +9 -4
- package/lib/staking/validators/index.d.ts.map +1 -1
- package/lib/staking/validators/index.js +19 -10
- package/lib/staking/validators/index.js.map +1 -1
- package/lib/staking/validators/monad.d.ts +6 -5
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js +33 -29
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/monadResolver.d.ts +2 -1
- package/lib/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib/staking/validators/monadResolver.js +2 -3
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib/staking/validators/somnia.d.ts +3 -2
- package/lib/staking/validators/somnia.d.ts.map +1 -1
- package/lib/staking/validators/somnia.js +16 -15
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/types.d.ts +2 -1
- package/lib/staking/validators/types.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.d.ts +2 -1
- package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.js +7 -8
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib/types/staking.d.ts +4 -3
- package/lib/types/staking.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.d.ts +4 -3
- package/lib-es/adapters/blockOperations.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.js +17 -17
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/adapters/etherscan.d.ts +7 -6
- package/lib-es/adapters/etherscan.d.ts.map +1 -1
- package/lib-es/adapters/etherscan.js +19 -19
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/adapters/ledger.d.ts +6 -5
- package/lib-es/adapters/ledger.d.ts.map +1 -1
- package/lib-es/adapters/ledger.js +15 -15
- 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 +1 -2
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/config.d.ts +0 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/logic/common.js +1 -1
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js +3 -3
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +22 -23
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getStakes.d.ts.map +1 -1
- package/lib-es/logic/getStakes.js +2 -2
- package/lib-es/logic/getStakes.js.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts +3 -2
- package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js +13 -10
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/listOperations.js +1 -1
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic-public/utils.d.ts +3 -2
- package/lib-es/logic-public/utils.d.ts.map +1 -1
- package/lib-es/logic-public/utils.js +7 -6
- package/lib-es/logic-public/utils.js.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +3 -2
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js +13 -12
- 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 +11 -11
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +2 -2
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/explorer/types.js.map +1 -1
- package/lib-es/network/node/explorerProxy.js +3 -3
- package/lib-es/network/node/explorerProxy.js.map +1 -1
- package/lib-es/network/node/index.d.ts.map +1 -1
- package/lib-es/network/node/index.js +2 -2
- package/lib-es/network/node/index.js.map +1 -1
- package/lib-es/network/node/ledger.d.ts +2 -1
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js +9 -10
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +3 -2
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +37 -29
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/staking/contracts.js +2 -2
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/fetchers.d.ts.map +1 -1
- package/lib-es/staking/fetchers.js +7 -7
- package/lib-es/staking/fetchers.js.map +1 -1
- package/lib-es/staking/prepareIntents.d.ts +2 -1
- package/lib-es/staking/prepareIntents.d.ts.map +1 -1
- package/lib-es/staking/prepareIntents.js +4 -4
- package/lib-es/staking/prepareIntents.js.map +1 -1
- package/lib-es/staking/redelegations.d.ts +5 -4
- package/lib-es/staking/redelegations.d.ts.map +1 -1
- package/lib-es/staking/redelegations.js +13 -14
- package/lib-es/staking/redelegations.js.map +1 -1
- package/lib-es/staking/rewards.d.ts +2 -1
- package/lib-es/staking/rewards.d.ts.map +1 -1
- package/lib-es/staking/rewards.js +4 -5
- package/lib-es/staking/rewards.js.map +1 -1
- package/lib-es/staking/rewardsFromReceipt.d.ts +2 -1
- package/lib-es/staking/rewardsFromReceipt.d.ts.map +1 -1
- package/lib-es/staking/rewardsFromReceipt.js +2 -3
- package/lib-es/staking/rewardsFromReceipt.js.map +1 -1
- package/lib-es/staking/unbondings.d.ts +2 -1
- package/lib-es/staking/unbondings.d.ts.map +1 -1
- package/lib-es/staking/unbondings.js +4 -5
- package/lib-es/staking/unbondings.js.map +1 -1
- package/lib-es/staking/validators/index.d.ts +9 -4
- package/lib-es/staking/validators/index.d.ts.map +1 -1
- package/lib-es/staking/validators/index.js +18 -10
- package/lib-es/staking/validators/index.js.map +1 -1
- package/lib-es/staking/validators/monad.d.ts +6 -5
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js +33 -29
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.d.ts +2 -1
- package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib-es/staking/validators/monadResolver.js +2 -3
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/staking/validators/somnia.d.ts +3 -2
- package/lib-es/staking/validators/somnia.d.ts.map +1 -1
- package/lib-es/staking/validators/somnia.js +16 -15
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/types.d.ts +2 -1
- package/lib-es/staking/validators/types.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.d.ts +2 -1
- package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js +7 -8
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/types/staking.d.ts +4 -3
- package/lib-es/types/staking.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/adapters/blockOperations.test.ts +86 -67
- package/src/adapters/blockOperations.ts +28 -17
- package/src/adapters/etherscan.test.ts +151 -85
- package/src/adapters/etherscan.ts +27 -18
- package/src/adapters/ledger.test.ts +210 -83
- package/src/adapters/ledger.ts +21 -15
- package/src/api/getBlock.integ.test.ts +10 -4
- package/src/api/index.arbitrum.integ.test.ts +1 -0
- package/src/api/index.arc.integ.test.ts +1 -0
- package/src/api/index.avalanche_c_chain_fuji.integ.test.ts +1 -0
- package/src/api/index.cronos.integ.test.ts +1 -0
- package/src/api/index.flare.integ.test.ts +4 -2
- package/src/api/index.integ.test.ts +7 -6
- package/src/api/index.linea.integ.test.ts +4 -2
- package/src/api/index.optimism.integ.test.ts +1 -0
- package/src/api/index.rsk.integ.test.ts +1 -0
- package/src/api/index.shape.integ.test.ts +4 -2
- package/src/api/index.somnia.integ.test.ts +1 -0
- package/src/api/index.test.ts +2 -2
- package/src/api/index.ts +1 -2
- package/src/config.ts +0 -1
- package/src/fixtures/context.fixtures.ts +5 -5
- package/src/logic/common.ts +1 -1
- package/src/logic/getBalance.ts +4 -3
- package/src/logic/getBlock.ts +43 -27
- package/src/logic/getStakes.ts +2 -1
- package/src/logic/internalTransactionsFetcher.ts +16 -10
- package/src/logic/listOperations.ts +2 -2
- package/src/logic/tests/getBalance.test.ts +5 -3
- package/src/logic/tests/getBlock.test.ts +16 -15
- package/src/logic/tests/internalTransactionsFetcher.test.ts +6 -5
- package/src/logic/tests/listOperations.test.ts +4 -4
- package/src/logic-public/tests/utils.test.ts +6 -5
- package/src/logic-public/utils.ts +8 -5
- package/src/logic.test.ts +5 -5
- package/src/network/explorer/etherscan.test.ts +169 -55
- package/src/network/explorer/etherscan.ts +27 -16
- package/src/network/explorer/index.test.ts +2 -1
- package/src/network/explorer/ledger.test.ts +208 -35
- package/src/network/explorer/ledger.ts +12 -8
- package/src/network/explorer/types.ts +3 -2
- package/src/network/node/explorerProxy.ts +3 -3
- package/src/network/node/index.ts +3 -2
- package/src/network/node/ledger.test.ts +25 -25
- package/src/network/node/ledger.ts +13 -10
- package/src/network/node/node.fixtures.ts +2 -1
- package/src/network/node/rpc.common.ts +84 -28
- package/src/network/node/rpc.test.ts +45 -31
- package/src/staking/contracts.ts +2 -2
- package/src/staking/fetchers.ts +20 -8
- package/src/staking/prepareIntents.test.ts +33 -12
- package/src/staking/prepareIntents.ts +9 -5
- package/src/staking/redelegations.test.ts +98 -35
- package/src/staking/redelegations.ts +20 -12
- package/src/staking/rewards.test.ts +15 -10
- package/src/staking/rewards.ts +8 -5
- package/src/staking/rewardsFromReceipt.test.ts +5 -4
- package/src/staking/rewardsFromReceipt.ts +4 -3
- package/src/staking/unbondings.test.ts +16 -12
- package/src/staking/unbondings.ts +7 -5
- package/src/staking/validators/index.ts +30 -10
- package/src/staking/validators/monad.test.ts +57 -43
- package/src/staking/validators/monad.ts +55 -32
- package/src/staking/validators/monadResolver.ts +4 -3
- package/src/staking/validators/somnia.test.ts +14 -13
- package/src/staking/validators/somnia.ts +35 -19
- package/src/staking/validators/types.ts +2 -0
- package/src/staking/validators/zero_gravity.test.ts +48 -26
- package/src/staking/validators/zero_gravity.ts +14 -8
- package/src/staking/validators.integ.test.ts +2 -2
- package/src/staking/validators.test.ts +31 -26
- package/src/types/staking.ts +9 -2
|
@@ -41,12 +41,13 @@ export const getNodeApi = (config: EvmConfigInfo, currencyId: string, logger: Lo
|
|
|
41
41
|
const clientVersion = config.ledgerClientVersion ?? ''
|
|
42
42
|
const nodeSources = JSON.stringify(config.nodeSources ?? ['node'])
|
|
43
43
|
const key = cacheKey(currencyId, node, explorerUri, clientVersion, nodeSources)
|
|
44
|
+
|
|
44
45
|
let api = nodeApiCache.get(key)
|
|
45
46
|
if (api === undefined) {
|
|
46
47
|
const raw =
|
|
47
48
|
type === 'ledger'
|
|
48
|
-
? createLedgerNodeApi({ ...node, explorerUri, clientVersion })
|
|
49
|
-
: createNodeApi(config, node)
|
|
49
|
+
? createLedgerNodeApi({ ...node, explorerUri, clientVersion }, logger)
|
|
50
|
+
: createNodeApi(config, node, logger)
|
|
50
51
|
api = withNodeSources(raw, config, logger)
|
|
51
52
|
nodeApiCache.set(key, api)
|
|
52
53
|
}
|
|
@@ -7,7 +7,7 @@ import BigNumber from 'bignumber.js'
|
|
|
7
7
|
import { Transaction } from 'ethers'
|
|
8
8
|
import { DEFAULT_LEDGER_EXPLORER_URI } from '../../config'
|
|
9
9
|
import { GasEstimationError } from '../../errors'
|
|
10
|
-
import { createMockEvmConfigInfo } from '../../fixtures/context.fixtures'
|
|
10
|
+
import { createMockEvmConfigInfo, testLogger } from '../../fixtures/context.fixtures'
|
|
11
11
|
import { getGasOptions } from '../gasTracker/ledger'
|
|
12
12
|
import { createLedgerNodeApi } from './ledger'
|
|
13
13
|
|
|
@@ -50,7 +50,7 @@ describe('EVM Family', () => {
|
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
it('reads a contract through the explorer contract/read endpoint', async () => {
|
|
53
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
53
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
54
54
|
const spy = jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
55
55
|
data: [
|
|
56
56
|
{
|
|
@@ -73,7 +73,7 @@ describe('EVM Family', () => {
|
|
|
73
73
|
})
|
|
74
74
|
|
|
75
75
|
it('forwards the requested block', async () => {
|
|
76
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
76
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
77
77
|
const spy = jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
78
78
|
data: [
|
|
79
79
|
{
|
|
@@ -93,7 +93,7 @@ describe('EVM Family', () => {
|
|
|
93
93
|
})
|
|
94
94
|
|
|
95
95
|
it('throws when the node reports a failure (e.g. revert)', async () => {
|
|
96
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
96
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
97
97
|
jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
98
98
|
data: [
|
|
99
99
|
{
|
|
@@ -111,7 +111,7 @@ describe('EVM Family', () => {
|
|
|
111
111
|
|
|
112
112
|
describe('createLedgerNodeApi / retries', () => {
|
|
113
113
|
it('should retry on fail', async () => {
|
|
114
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
114
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
115
115
|
let attempts = 2
|
|
116
116
|
const spy = jest.spyOn(axios, 'request').mockImplementation(async () => {
|
|
117
117
|
if (attempts) {
|
|
@@ -139,7 +139,7 @@ describe('EVM Family', () => {
|
|
|
139
139
|
})
|
|
140
140
|
|
|
141
141
|
it('should throw after too many retries', async () => {
|
|
142
|
-
const api = createLedgerNodeApi({ ...ledgerConfig, retries: 2 })
|
|
142
|
+
const api = createLedgerNodeApi({ ...ledgerConfig, retries: 2 }, testLogger)
|
|
143
143
|
const SpyError = class SpyError extends Error {}
|
|
144
144
|
let attempts = 3
|
|
145
145
|
jest.spyOn(axios, 'request').mockImplementation(async () => {
|
|
@@ -155,7 +155,7 @@ describe('EVM Family', () => {
|
|
|
155
155
|
|
|
156
156
|
describe('getTransaction', () => {
|
|
157
157
|
it('should return the expected payload', async () => {
|
|
158
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
158
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
159
159
|
jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
160
160
|
data: {
|
|
161
161
|
hash: '0x8d5ef4d7673fbfa6a4755cdfdb913742c47c7fdac2d214046387bbcbf10957c9',
|
|
@@ -239,7 +239,7 @@ describe('EVM Family', () => {
|
|
|
239
239
|
|
|
240
240
|
describe('getCoinBalance', () => {
|
|
241
241
|
it('should return the expected payload', async () => {
|
|
242
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
242
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
243
243
|
jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
244
244
|
data: { balance: '6969' },
|
|
245
245
|
}))
|
|
@@ -250,7 +250,7 @@ describe('EVM Family', () => {
|
|
|
250
250
|
|
|
251
251
|
describe('getTokenBalance', () => {
|
|
252
252
|
it('should return the expected payload', async () => {
|
|
253
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
253
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
254
254
|
jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
255
255
|
data: [
|
|
256
256
|
{ address: '0xkvn', contract: '0xusdc', balance: '6969' },
|
|
@@ -266,7 +266,7 @@ describe('EVM Family', () => {
|
|
|
266
266
|
|
|
267
267
|
describe('getTransactionCount', () => {
|
|
268
268
|
it('should return the expected payload', async () => {
|
|
269
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
269
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
270
270
|
jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
271
271
|
data: { address: '0xkvn', nonce: 123 },
|
|
272
272
|
}))
|
|
@@ -277,7 +277,7 @@ describe('EVM Family', () => {
|
|
|
277
277
|
|
|
278
278
|
describe('getGasEstimation', () => {
|
|
279
279
|
it('should throw GasEstimationError on failure', async () => {
|
|
280
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
280
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
281
281
|
jest.spyOn(axios, 'request').mockImplementation(async () => {
|
|
282
282
|
throw new Error()
|
|
283
283
|
})
|
|
@@ -288,7 +288,7 @@ describe('EVM Family', () => {
|
|
|
288
288
|
})
|
|
289
289
|
|
|
290
290
|
it('should throw GasEstimationError if request throws ECONNABORTED', async () => {
|
|
291
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
291
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
292
292
|
jest
|
|
293
293
|
.spyOn(axios, 'request')
|
|
294
294
|
.mockImplementation(() => Promise.reject({ code: 'ECONNABORTED' }))
|
|
@@ -299,7 +299,7 @@ describe('EVM Family', () => {
|
|
|
299
299
|
})
|
|
300
300
|
|
|
301
301
|
it('should return the expected payload', async () => {
|
|
302
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
302
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
303
303
|
jest
|
|
304
304
|
.spyOn(axios, 'request')
|
|
305
305
|
.mockResolvedValueOnce({ data: { to: '0xBob', estimated_gas_limit: '789' } })
|
|
@@ -332,7 +332,7 @@ describe('EVM Family', () => {
|
|
|
332
332
|
|
|
333
333
|
describe('getFeeData', () => {
|
|
334
334
|
it("should return the fee data based on the transaction's feesStrategy", async () => {
|
|
335
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
335
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
336
336
|
mockGetGasOptions.mockImplementation(async () => ({
|
|
337
337
|
slow: {
|
|
338
338
|
maxFeePerGas: new BigNumber(1),
|
|
@@ -400,7 +400,7 @@ describe('EVM Family', () => {
|
|
|
400
400
|
})
|
|
401
401
|
|
|
402
402
|
it('should return medium fee data if feesStrategy is not provided', async () => {
|
|
403
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
403
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
404
404
|
mockGetGasOptions.mockImplementation(async () => ({
|
|
405
405
|
slow: {
|
|
406
406
|
maxFeePerGas: new BigNumber(1),
|
|
@@ -439,7 +439,7 @@ describe('EVM Family', () => {
|
|
|
439
439
|
|
|
440
440
|
describe('broadcastTransaction', () => {
|
|
441
441
|
it('should return the expected payload', async () => {
|
|
442
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
442
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
443
443
|
jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
444
444
|
data: {
|
|
445
445
|
result: '0xHash',
|
|
@@ -450,7 +450,7 @@ describe('EVM Family', () => {
|
|
|
450
450
|
})
|
|
451
451
|
|
|
452
452
|
it('should include mevProtected=true in the request parameters when specified', async () => {
|
|
453
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
453
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
454
454
|
const mockRequest = jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
455
455
|
data: {
|
|
456
456
|
result: '0xHash',
|
|
@@ -471,7 +471,7 @@ describe('EVM Family', () => {
|
|
|
471
471
|
})
|
|
472
472
|
|
|
473
473
|
it('should include source headers when source is provided', async () => {
|
|
474
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
474
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
475
475
|
const mockRequest = jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
476
476
|
data: {
|
|
477
477
|
result: '0xHash',
|
|
@@ -496,7 +496,7 @@ describe('EVM Family', () => {
|
|
|
496
496
|
})
|
|
497
497
|
|
|
498
498
|
it('should not include source headers when source is not provided', async () => {
|
|
499
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
499
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
500
500
|
const mockRequest = jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
501
501
|
data: {
|
|
502
502
|
result: '0xHash',
|
|
@@ -518,7 +518,7 @@ describe('EVM Family', () => {
|
|
|
518
518
|
|
|
519
519
|
describe('getBlockByHeight', () => {
|
|
520
520
|
it('should return the expected payload', async () => {
|
|
521
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
521
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
522
522
|
jest.spyOn(axios, 'request').mockImplementation(async ({ url }) => {
|
|
523
523
|
if (url?.endsWith('current')) {
|
|
524
524
|
return {
|
|
@@ -563,12 +563,12 @@ describe('EVM Family', () => {
|
|
|
563
563
|
|
|
564
564
|
describe('getOptimismAdditionalFees', () => {
|
|
565
565
|
it('should return 0 for an incompatible currency', async () => {
|
|
566
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
566
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
567
567
|
expect(await api.getOptimismAdditionalFees(currencyId, '')).toEqual(new BigNumber(0))
|
|
568
568
|
})
|
|
569
569
|
|
|
570
570
|
it('should return the expected payload', async () => {
|
|
571
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
571
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
572
572
|
jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
573
573
|
data: [
|
|
574
574
|
{
|
|
@@ -605,7 +605,7 @@ describe('EVM Family', () => {
|
|
|
605
605
|
it.each(['blast', 'blast_sepolia', 'base', 'base_sepolia'])(
|
|
606
606
|
'should query the OP-stack gas oracle for %s (not return 0)',
|
|
607
607
|
async (currencyId) => {
|
|
608
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
608
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
609
609
|
jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
610
610
|
data: [
|
|
611
611
|
{
|
|
@@ -643,12 +643,12 @@ describe('EVM Family', () => {
|
|
|
643
643
|
|
|
644
644
|
describe('getScrollAdditionalFees', () => {
|
|
645
645
|
it('should return 0 for an incompatible currency', async () => {
|
|
646
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
646
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
647
647
|
expect(await api.getScrollAdditionalFees(currencyId, '')).toEqual(new BigNumber(0))
|
|
648
648
|
})
|
|
649
649
|
|
|
650
650
|
it('should return the expected payload', async () => {
|
|
651
|
-
const api = createLedgerNodeApi(ledgerConfig)
|
|
651
|
+
const api = createLedgerNodeApi(ledgerConfig, testLogger)
|
|
652
652
|
jest.spyOn(axios, 'request').mockImplementationOnce(async () => ({
|
|
653
653
|
data: [
|
|
654
654
|
{
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
import type { BlockFinalizationTag, LedgerNodeConfig } from '../../config'
|
|
5
5
|
import type { LedgerExplorerOperation } from '../../types'
|
|
6
6
|
import type { BlockByHeightResult, EvmCallParams, NodeApi, TransactionInfo } from './types'
|
|
7
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
7
8
|
import type { Batcher } from '@ledgerhq/live-network/batcher/types'
|
|
8
9
|
import type { AxiosRequestConfig } from 'axios'
|
|
9
10
|
import { makeBatcher } from '@ledgerhq/live-network/batcher/index'
|
|
10
|
-
import { log } from '@ledgerhq/logs'
|
|
11
11
|
import axios from 'axios'
|
|
12
12
|
import BigNumber from 'bignumber.js'
|
|
13
13
|
import { ethers } from 'ethers'
|
|
@@ -62,7 +62,8 @@ async function getTransaction(
|
|
|
62
62
|
fetch: LedgerFetch,
|
|
63
63
|
config: LedgerNodeApiConfig,
|
|
64
64
|
_currencyId: string,
|
|
65
|
-
hash: string
|
|
65
|
+
hash: string,
|
|
66
|
+
logger: Logger
|
|
66
67
|
): Promise<TransactionInfo> {
|
|
67
68
|
const ledgerTransaction = await fetch<LedgerExplorerOperation>({
|
|
68
69
|
method: 'GET',
|
|
@@ -83,10 +84,10 @@ async function getTransaction(
|
|
|
83
84
|
erc20Transfers: ledgerTransaction.transfer_events.map((event) => ({
|
|
84
85
|
asset: {
|
|
85
86
|
type: 'erc20' as const,
|
|
86
|
-
assetReference: safeEncodeEIP55(event.contract),
|
|
87
|
+
assetReference: safeEncodeEIP55(event.contract, logger),
|
|
87
88
|
},
|
|
88
|
-
from: safeEncodeEIP55(event.from),
|
|
89
|
-
to: safeEncodeEIP55(event.to),
|
|
89
|
+
from: safeEncodeEIP55(event.from, logger),
|
|
90
|
+
to: safeEncodeEIP55(event.to, logger),
|
|
90
91
|
value: event.count,
|
|
91
92
|
})),
|
|
92
93
|
}
|
|
@@ -167,7 +168,8 @@ async function getTransactionCount(
|
|
|
167
168
|
|
|
168
169
|
function makeGetGasEstimation(
|
|
169
170
|
config: LedgerNodeApiConfig,
|
|
170
|
-
fetch: LedgerFetch
|
|
171
|
+
fetch: LedgerFetch,
|
|
172
|
+
logger: Logger
|
|
171
173
|
): NodeApi['getGasEstimation'] {
|
|
172
174
|
return async (_currencyId, address, transaction) => {
|
|
173
175
|
const { recipient: to, amount: value, data } = transaction
|
|
@@ -188,7 +190,7 @@ function makeGetGasEstimation(
|
|
|
188
190
|
})
|
|
189
191
|
return new BigNumber(gasEstimation)
|
|
190
192
|
} catch (e) {
|
|
191
|
-
|
|
193
|
+
logger('error', 'EVM Family: Gas Estimation Error', e)
|
|
192
194
|
throw new GasEstimationError()
|
|
193
195
|
}
|
|
194
196
|
}
|
|
@@ -419,7 +421,7 @@ async function getScrollAdditionalFees(
|
|
|
419
421
|
return new BigNumber(result.response)
|
|
420
422
|
}
|
|
421
423
|
|
|
422
|
-
export function createLedgerNodeApi(config: LedgerNodeApiConfig): NodeApi {
|
|
424
|
+
export function createLedgerNodeApi(config: LedgerNodeApiConfig, logger: Logger): NodeApi {
|
|
423
425
|
const fetch = makeFetchWithRetries(config)
|
|
424
426
|
const tokenBalancesBatchersMap = new Map<
|
|
425
427
|
string,
|
|
@@ -432,8 +434,9 @@ export function createLedgerNodeApi(config: LedgerNodeApiConfig): NodeApi {
|
|
|
432
434
|
getTokenBalance: makeGetTokenBalance(config, fetch, tokenBalancesBatchersMap),
|
|
433
435
|
getTokenAllowance: makeGetTokenAllowance(config, fetch),
|
|
434
436
|
getTransactionCount: make(getTransactionCount, config, fetch),
|
|
435
|
-
getTransaction:
|
|
436
|
-
|
|
437
|
+
getTransaction: ((currencyId, hash) =>
|
|
438
|
+
getTransaction(fetch, config, currencyId, hash, logger)) as NodeApi['getTransaction'],
|
|
439
|
+
getGasEstimation: makeGetGasEstimation(config, fetch, logger),
|
|
437
440
|
// getFeeData takes `config` (EvmConfigInfo) first, not `currency`, so it doesn't fit the
|
|
438
441
|
// currency-first `make` type bound; bind it directly (same fetch/config passthrough as `make`).
|
|
439
442
|
getFeeData: ((...args: Parameters<NodeApi['getFeeData']>) =>
|
|
@@ -5,6 +5,7 @@ import type { NodeApi } from './types'
|
|
|
5
5
|
|
|
6
6
|
export function mockNodeApi(overrides: Partial<jest.Mocked<NodeApi>> = {}): jest.Mocked<NodeApi> {
|
|
7
7
|
return {
|
|
8
|
+
call: jest.fn(),
|
|
8
9
|
getTransaction: jest.fn(),
|
|
9
10
|
getCoinBalance: jest.fn(),
|
|
10
11
|
getTokenBalance: jest.fn(),
|
|
@@ -18,5 +19,5 @@ export function mockNodeApi(overrides: Partial<jest.Mocked<NodeApi>> = {}): jest
|
|
|
18
19
|
getOptimismAdditionalFees: jest.fn(),
|
|
19
20
|
getScrollAdditionalFees: jest.fn(),
|
|
20
21
|
...overrides,
|
|
21
|
-
}
|
|
22
|
+
}
|
|
22
23
|
}
|
|
@@ -15,9 +15,9 @@ import type {
|
|
|
15
15
|
BlockReceiptInfo,
|
|
16
16
|
EvmCallParams,
|
|
17
17
|
} from './types'
|
|
18
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
18
19
|
/** ⚠️ keep this order of import. @see https://docs.ethers.io/v5/cookbook/react-native/#cookbook-reactnative ⚠️ */
|
|
19
20
|
import { makeLRUCache } from '@ledgerhq/live-network/cache'
|
|
20
|
-
import { log } from '@ledgerhq/logs'
|
|
21
21
|
import BigNumber from 'bignumber.js'
|
|
22
22
|
import { ethers, FetchRequest, JsonRpcProvider } from 'ethers'
|
|
23
23
|
import ERC20Abi from '../../abis/erc20.abi.json'
|
|
@@ -58,15 +58,16 @@ export const ERC20_MINT_TOPIC = '0x0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea
|
|
|
58
58
|
/** Emitter of the native transfer logs added by https://eips.ethereum.org/EIPS/eip-7708. */
|
|
59
59
|
export const SYSTEM_ADDRESS = '0xfffffffffffffffffffffffffffffffffffffffe'
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
/** All-zeros address; already EIP-55 checksummed since it contains no hex letters. */
|
|
62
|
+
const ZERO_ADDRESS_HEX = '0x0000000000000000000000000000000000000000'
|
|
62
63
|
|
|
63
64
|
function isSystemLog(log: LogWithAddress): boolean {
|
|
64
65
|
return normalizeAddress(log.address) === SYSTEM_ADDRESS
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
function topicToAddress(topic: string | undefined): string {
|
|
68
|
+
function topicToAddress(topic: string | undefined, logger: Logger): string {
|
|
68
69
|
if (!topic || topic.length < 66) return ZERO_ADDRESS_HEX
|
|
69
|
-
return safeEncodeEIP55('0x' + topic.slice(26))
|
|
70
|
+
return safeEncodeEIP55('0x' + topic.slice(26), logger)
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
function isTransfer(log: LogWithAddress): boolean {
|
|
@@ -85,11 +86,16 @@ function isMint(log: LogWithAddress): boolean {
|
|
|
85
86
|
return log.topics[0] === ERC20_MINT_TOPIC && log.topics.length === 2 && log.data.length > 2
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
function makeErc20Transfer(
|
|
89
|
+
function makeErc20Transfer(
|
|
90
|
+
log: LogWithAddress,
|
|
91
|
+
from: string,
|
|
92
|
+
to: string,
|
|
93
|
+
logger: Logger
|
|
94
|
+
): ERC20Transfer {
|
|
89
95
|
return {
|
|
90
96
|
asset: {
|
|
91
97
|
type: 'erc20',
|
|
92
|
-
assetReference: safeEncodeEIP55(log.address),
|
|
98
|
+
assetReference: safeEncodeEIP55(log.address, logger),
|
|
93
99
|
},
|
|
94
100
|
from,
|
|
95
101
|
to,
|
|
@@ -131,23 +137,39 @@ function makeErc20Transfer(log: LogWithAddress, from: string, to: string): ERC20
|
|
|
131
137
|
* @param logs - Array of logs from transaction receipt
|
|
132
138
|
* @returns Array of parsed ERC20 transfers
|
|
133
139
|
*/
|
|
134
|
-
export function parseERC20TransfersFromLogs(
|
|
140
|
+
export function parseERC20TransfersFromLogs(
|
|
141
|
+
logs: ReadonlyArray<LogWithAddress>,
|
|
142
|
+
logger: Logger
|
|
143
|
+
): ERC20Transfer[] {
|
|
135
144
|
return logs.flatMap((log) => {
|
|
136
145
|
// These mimic an ERC20 `Transfer` on a token that does not exist.
|
|
137
146
|
if (isSystemLog(log)) {
|
|
138
147
|
return []
|
|
139
148
|
}
|
|
140
149
|
if (isTransfer(log)) {
|
|
141
|
-
return [
|
|
150
|
+
return [
|
|
151
|
+
makeErc20Transfer(
|
|
152
|
+
log,
|
|
153
|
+
topicToAddress(log.topics[1], logger),
|
|
154
|
+
topicToAddress(log.topics[2], logger),
|
|
155
|
+
logger
|
|
156
|
+
),
|
|
157
|
+
]
|
|
142
158
|
}
|
|
143
159
|
if (isWethDeposit(log)) {
|
|
144
|
-
return [
|
|
160
|
+
return [
|
|
161
|
+
makeErc20Transfer(log, ZERO_ADDRESS_HEX, topicToAddress(log.topics[1], logger), logger),
|
|
162
|
+
]
|
|
145
163
|
}
|
|
146
164
|
if (isWethWithdrawal(log)) {
|
|
147
|
-
return [
|
|
165
|
+
return [
|
|
166
|
+
makeErc20Transfer(log, topicToAddress(log.topics[1], logger), ZERO_ADDRESS_HEX, logger),
|
|
167
|
+
]
|
|
148
168
|
}
|
|
149
169
|
if (isMint(log)) {
|
|
150
|
-
return [
|
|
170
|
+
return [
|
|
171
|
+
makeErc20Transfer(log, ZERO_ADDRESS_HEX, topicToAddress(log.topics[1], logger), logger),
|
|
172
|
+
]
|
|
151
173
|
}
|
|
152
174
|
return []
|
|
153
175
|
})
|
|
@@ -239,7 +261,8 @@ function parseReceiptL1Fee(raw: Record<string, unknown>): string | undefined {
|
|
|
239
261
|
async function getTransaction(
|
|
240
262
|
api: JsonRpcProvider,
|
|
241
263
|
_currencyId: string,
|
|
242
|
-
txHash: string
|
|
264
|
+
txHash: string,
|
|
265
|
+
logger: Logger
|
|
243
266
|
): Promise<TransactionInfo> {
|
|
244
267
|
// Note: raw RPC call is used to get transaction receipt, as ethers method drops extra fields. We need optimism's
|
|
245
268
|
// extra fields that contain L1 fees.
|
|
@@ -278,7 +301,7 @@ async function getTransaction(
|
|
|
278
301
|
? { input: tx.data }
|
|
279
302
|
: {}),
|
|
280
303
|
...(contractAddress ? { contractAddress } : {}),
|
|
281
|
-
erc20Transfers: parseERC20TransfersFromLogs(receipt.logs),
|
|
304
|
+
erc20Transfers: parseERC20TransfersFromLogs(receipt.logs, logger),
|
|
282
305
|
...(l1Fee !== undefined ? { l1Fee } : {}),
|
|
283
306
|
}
|
|
284
307
|
}
|
|
@@ -344,7 +367,8 @@ async function getTransactionCount(
|
|
|
344
367
|
async function getGasEstimation(
|
|
345
368
|
api: JsonRpcProvider,
|
|
346
369
|
address: string,
|
|
347
|
-
transaction: { amount: BigNumber; data?: Buffer | null | undefined; recipient: string }
|
|
370
|
+
transaction: { amount: BigNumber; data?: Buffer | null | undefined; recipient: string },
|
|
371
|
+
logger: Logger
|
|
348
372
|
): Promise<BigNumber> {
|
|
349
373
|
const to = transaction.recipient ? normalizeAddress(transaction.recipient) : undefined
|
|
350
374
|
const value = BigInt(transaction.amount.toFixed(0))
|
|
@@ -359,17 +383,18 @@ async function getGasEstimation(
|
|
|
359
383
|
|
|
360
384
|
return new BigNumber(gasEstimation.toString())
|
|
361
385
|
} catch (e) {
|
|
362
|
-
|
|
386
|
+
logger('error', 'EVM Family: Gas Estimation Error', e)
|
|
363
387
|
throw new GasEstimationError()
|
|
364
388
|
}
|
|
365
389
|
}
|
|
366
390
|
|
|
367
391
|
function makeGetGasEstimation(
|
|
368
392
|
evmConfig: EvmConfigInfo,
|
|
369
|
-
nodeConfig: ExternalNodeConfig
|
|
393
|
+
nodeConfig: ExternalNodeConfig,
|
|
394
|
+
logger: Logger
|
|
370
395
|
): NodeApi['getGasEstimation'] {
|
|
371
396
|
return (currencyId, address, transaction) =>
|
|
372
|
-
withApi(evmConfig, currencyId, (api) => getGasEstimation(api, address, transaction), {
|
|
397
|
+
withApi(evmConfig, currencyId, (api) => getGasEstimation(api, address, transaction, logger), {
|
|
373
398
|
...nodeConfig,
|
|
374
399
|
retries: 0,
|
|
375
400
|
})
|
|
@@ -491,14 +516,15 @@ async function getFeeData(
|
|
|
491
516
|
async function broadcastTransaction(
|
|
492
517
|
api: JsonRpcProvider,
|
|
493
518
|
_currencyId: string,
|
|
494
|
-
signedTxHex: string
|
|
519
|
+
signedTxHex: string,
|
|
520
|
+
logger: Logger
|
|
495
521
|
): Promise<string> {
|
|
496
522
|
try {
|
|
497
523
|
const { hash } = await api.broadcastTransaction(signedTxHex)
|
|
498
524
|
return hash
|
|
499
525
|
} catch (e) {
|
|
500
526
|
if (hasErrorCode(e, 'INSUFFICIENT_FUNDS')) {
|
|
501
|
-
|
|
527
|
+
logger('error', 'EVM Family: Wrong estimation of fees', e)
|
|
502
528
|
throw new InsufficientFunds()
|
|
503
529
|
}
|
|
504
530
|
throw e
|
|
@@ -509,6 +535,7 @@ async function getBlockByHeight(
|
|
|
509
535
|
api: JsonRpcProvider,
|
|
510
536
|
_currencyId: string,
|
|
511
537
|
blockHeight: number | BlockFinalizationTag,
|
|
538
|
+
logger: Logger,
|
|
512
539
|
prefetchTxs?: boolean
|
|
513
540
|
): Promise<BlockByHeightResult> {
|
|
514
541
|
let block: ethers.Block | null
|
|
@@ -518,7 +545,7 @@ async function getBlockByHeight(
|
|
|
518
545
|
// Some chains (e.g. zkSync) can return tx objects missing signature fields, ethers then fails while formatting
|
|
519
546
|
// prefetched transactions => we fallback to a custom getBlock implementation
|
|
520
547
|
if (prefetchTxs && isSignatureError(error)) {
|
|
521
|
-
|
|
548
|
+
logger('warn', 'EVM getBlock fallback: using raw eth_getBlockByNumber response', {
|
|
522
549
|
blockHeight,
|
|
523
550
|
error: String(error),
|
|
524
551
|
})
|
|
@@ -704,7 +731,8 @@ async function getBlockByHeightFromRawRpc(
|
|
|
704
731
|
async function getBlockReceipts(
|
|
705
732
|
api: JsonRpcProvider,
|
|
706
733
|
_currencyId: string,
|
|
707
|
-
blockHeight: number | 'latest'
|
|
734
|
+
blockHeight: number | 'latest',
|
|
735
|
+
logger: Logger
|
|
708
736
|
): Promise<BlockReceiptInfo[]> {
|
|
709
737
|
const blockTag = blockHeight === 'latest' ? 'latest' : ethers.toQuantity(blockHeight)
|
|
710
738
|
let receipts: unknown
|
|
@@ -743,7 +771,7 @@ async function getBlockReceipts(
|
|
|
743
771
|
gasUsed: BigInt(receipt.gasUsed).toString(),
|
|
744
772
|
gasPrice: BigInt(receipt.effectiveGasPrice ?? receipt.gasPrice ?? '0x0').toString(),
|
|
745
773
|
status: receipt.status === null ? null : Number(receipt.status),
|
|
746
|
-
erc20Transfers: parseERC20TransfersFromLogs(receipt.logs),
|
|
774
|
+
erc20Transfers: parseERC20TransfersFromLogs(receipt.logs, logger),
|
|
747
775
|
...(contractAddress ? { contractAddress } : {}),
|
|
748
776
|
...(receipt.type !== undefined ? { type: Number(receipt.type) } : {}),
|
|
749
777
|
...(l1Fee !== undefined ? { l1Fee } : {}),
|
|
@@ -939,26 +967,54 @@ function make<F extends (currencyId: string, ...args: any[]) => any>(
|
|
|
939
967
|
}) as F
|
|
940
968
|
}
|
|
941
969
|
|
|
942
|
-
export function createNodeApi(
|
|
970
|
+
export function createNodeApi(
|
|
971
|
+
evmConfig: EvmConfigInfo,
|
|
972
|
+
nodeConfig: ExternalNodeConfig,
|
|
973
|
+
logger: Logger
|
|
974
|
+
): NodeApi {
|
|
943
975
|
return {
|
|
944
976
|
call: make(call, evmConfig, nodeConfig),
|
|
945
|
-
getBlockByHeight:
|
|
977
|
+
getBlockByHeight: ((currencyId, blockHeight, prefetchTxs) =>
|
|
978
|
+
withApi(
|
|
979
|
+
evmConfig,
|
|
980
|
+
currencyId,
|
|
981
|
+
(api) => getBlockByHeight(api, currencyId, blockHeight, logger, prefetchTxs),
|
|
982
|
+
nodeConfig
|
|
983
|
+
)) as NodeApi['getBlockByHeight'],
|
|
946
984
|
getCoinBalance: make(getCoinBalance, evmConfig, nodeConfig),
|
|
947
985
|
getTokenBalance: make(getTokenBalance, evmConfig, nodeConfig),
|
|
948
986
|
getTokenAllowance: make(getTokenAllowance, evmConfig, nodeConfig),
|
|
949
987
|
getTransactionCount: make(getTransactionCount, evmConfig, nodeConfig),
|
|
950
|
-
getTransaction:
|
|
951
|
-
|
|
988
|
+
getTransaction: ((currencyId, txHash) =>
|
|
989
|
+
withApi(
|
|
990
|
+
evmConfig,
|
|
991
|
+
currencyId,
|
|
992
|
+
(api) => getTransaction(api, currencyId, txHash, logger),
|
|
993
|
+
nodeConfig
|
|
994
|
+
)) as NodeApi['getTransaction'],
|
|
995
|
+
getBlockReceipts: ((currencyId, blockHeight) =>
|
|
996
|
+
withApi(
|
|
997
|
+
evmConfig,
|
|
998
|
+
currencyId,
|
|
999
|
+
(api) => getBlockReceipts(api, currencyId, blockHeight, logger),
|
|
1000
|
+
nodeConfig
|
|
1001
|
+
)) as NonNullable<NodeApi['getBlockReceipts']>,
|
|
952
1002
|
traceBlockErigon: make(traceBlockErigon, evmConfig, nodeConfig),
|
|
953
1003
|
traceBlockGeth: make(traceBlockGeth, evmConfig, nodeConfig),
|
|
954
|
-
getGasEstimation: makeGetGasEstimation(evmConfig, nodeConfig),
|
|
1004
|
+
getGasEstimation: makeGetGasEstimation(evmConfig, nodeConfig, logger),
|
|
955
1005
|
// getFeeData takes `config` first (not `currencyId`), so it can't use the currencyId-first
|
|
956
1006
|
// `make` wrapper; bind it explicitly and pull `currencyId` from the second argument for `withApi`.
|
|
957
1007
|
getFeeData: ((...args: Parameters<NodeApi['getFeeData']>) => {
|
|
958
1008
|
const [, currencyId] = args
|
|
959
1009
|
return withApi(evmConfig, currencyId, (api) => getFeeData(api, ...args), nodeConfig)
|
|
960
1010
|
}) as NodeApi['getFeeData'],
|
|
961
|
-
broadcastTransaction:
|
|
1011
|
+
broadcastTransaction: ((currencyId, signedTxHex) =>
|
|
1012
|
+
withApi(
|
|
1013
|
+
evmConfig,
|
|
1014
|
+
currencyId,
|
|
1015
|
+
(api) => broadcastTransaction(api, currencyId, signedTxHex, logger),
|
|
1016
|
+
{ ...nodeConfig, retries: 0 }
|
|
1017
|
+
)) as NodeApi['broadcastTransaction'],
|
|
962
1018
|
getOptimismAdditionalFees: makeLRUCache(
|
|
963
1019
|
make(getOptimismAdditionalFees, evmConfig, nodeConfig),
|
|
964
1020
|
cacheKeyOptimismL1Fees,
|