@ledgerhq/coin-evm 5.4.1 → 7.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/CHANGELOG.md +191 -0
- package/docs/evm-family-integration-process/README.md +1 -1
- package/knip.json +2 -3
- package/lib/adapters/blockOperations.js +6 -6
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/adapters/etherscan.js +23 -23
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/adapters/ledger.js +17 -17
- package/lib/adapters/ledger.js.map +1 -1
- package/lib/api/index.js +4 -4
- package/lib/api/index.js.map +1 -1
- package/lib/config.d.ts +21 -15
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +5 -25
- package/lib/config.js.map +1 -1
- package/lib/errors.d.ts +9 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +15 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/broadcast.js +1 -1
- package/lib/logic/broadcast.js.map +1 -1
- package/lib/logic/common.d.ts +2 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js +4 -4
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +2 -2
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +9 -9
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js +50 -16
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +19 -11
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getBlockInfo.js +1 -1
- package/lib/logic/getBlockInfo.js.map +1 -1
- package/lib/logic/getNextSequence.d.ts.map +1 -1
- package/lib/logic/getNextSequence.js +1 -1
- package/lib/logic/getNextSequence.js.map +1 -1
- package/lib/logic/index.d.ts +2 -0
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +4 -0
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/lastBlock.js +1 -1
- package/lib/logic/lastBlock.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +10 -1
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js +12 -12
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic-public/index.d.ts +3 -0
- package/lib/logic-public/index.d.ts.map +1 -0
- package/lib/logic-public/index.js +19 -0
- package/lib/logic-public/index.js.map +1 -0
- package/lib/{utils.d.ts → logic-public/utils.d.ts} +0 -44
- package/lib/logic-public/utils.d.ts.map +1 -0
- package/lib/logic-public/utils.js +166 -0
- package/lib/logic-public/utils.js.map +1 -0
- package/lib/logic.d.ts +2 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/logic.js +3 -3
- package/lib/logic.js.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +16 -3
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js +61 -6
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts +50 -4
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js +286 -37
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/none.d.ts +1 -0
- package/lib/network/explorer/none.d.ts.map +1 -1
- package/lib/network/explorer/none.js +4 -1
- package/lib/network/explorer/none.js.map +1 -1
- package/lib/network/explorer/types.d.ts +15 -2
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/explorer/types.js.map +1 -1
- package/lib/network/index.d.ts +5 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +23 -0
- package/lib/network/index.js.map +1 -0
- package/lib/network/node/explorerProxy.d.ts +27 -0
- package/lib/network/node/explorerProxy.d.ts.map +1 -0
- package/lib/network/node/explorerProxy.js +262 -0
- package/lib/network/node/explorerProxy.js.map +1 -0
- package/lib/network/node/index.d.ts +2 -1
- package/lib/network/node/index.d.ts.map +1 -1
- package/lib/network/node/index.js +11 -10
- package/lib/network/node/index.js.map +1 -1
- package/lib/network/node/ledger.js +7 -7
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +2 -2
- package/lib/network/node/rpc.common.js +19 -19
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/withNodeSources.d.ts +21 -0
- package/lib/network/node/withNodeSources.d.ts.map +1 -0
- package/lib/network/node/withNodeSources.js +78 -0
- package/lib/network/node/withNodeSources.js.map +1 -0
- package/lib/nodeSources.d.ts +15 -0
- package/lib/nodeSources.d.ts.map +1 -0
- package/lib/nodeSources.js +33 -0
- package/lib/nodeSources.js.map +1 -0
- package/lib/staking/contracts.js +1 -1
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/fetchers.js +1 -1
- package/lib/staking/fetchers.js.map +1 -1
- package/lib/staking/operations/sei.js +1 -1
- package/lib/staking/operations/sei.js.map +1 -1
- package/lib/staking/prepareIntents.js +3 -3
- package/lib/staking/prepareIntents.js.map +1 -1
- package/lib/staking/rewards.js +1 -1
- package/lib/staking/rewards.js.map +1 -1
- package/lib/staking/transactionData.js +2 -2
- package/lib/staking/transactionData.js.map +1 -1
- package/lib/staking/utils.d.ts +45 -0
- package/lib/staking/utils.d.ts.map +1 -0
- package/lib/{utils.js → staking/utils.js} +5 -164
- package/lib/staking/utils.js.map +1 -0
- package/lib/staking/validators/sei.js +1 -1
- package/lib/staking/validators/sei.js.map +1 -1
- package/lib/types/staking.d.ts +2 -2
- package/lib-es/adapters/blockOperations.js +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/adapters/etherscan.js +1 -1
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/adapters/ledger.js +1 -1
- package/lib-es/adapters/ledger.js.map +1 -1
- package/lib-es/api/index.js +2 -2
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/config.d.ts +21 -15
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +1 -21
- package/lib-es/config.js.map +1 -1
- package/lib-es/errors.d.ts +9 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +13 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/broadcast.js +1 -1
- package/lib-es/logic/broadcast.js.map +1 -1
- package/lib-es/logic/common.d.ts +2 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +3 -3
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +2 -2
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +6 -6
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js +50 -16
- 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 +16 -8
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getBlockInfo.js +1 -1
- package/lib-es/logic/getBlockInfo.js.map +1 -1
- package/lib-es/logic/getNextSequence.d.ts.map +1 -1
- package/lib-es/logic/getNextSequence.js +1 -1
- package/lib-es/logic/getNextSequence.js.map +1 -1
- package/lib-es/logic/index.d.ts +2 -0
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +4 -0
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/lastBlock.js +1 -1
- package/lib-es/logic/lastBlock.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +10 -1
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js +4 -4
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic-public/index.d.ts +3 -0
- package/lib-es/logic-public/index.d.ts.map +1 -0
- package/lib-es/logic-public/index.js +4 -0
- package/lib-es/logic-public/index.js.map +1 -0
- package/lib-es/{utils.d.ts → logic-public/utils.d.ts} +0 -44
- package/lib-es/logic-public/utils.d.ts.map +1 -0
- package/lib-es/logic-public/utils.js +150 -0
- package/lib-es/logic-public/utils.js.map +1 -0
- package/lib-es/logic.d.ts +2 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/logic.js +3 -3
- package/lib-es/logic.js.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +16 -3
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js +60 -5
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts +50 -4
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js +283 -37
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/none.d.ts +1 -0
- package/lib-es/network/explorer/none.d.ts.map +1 -1
- package/lib-es/network/explorer/none.js +2 -0
- package/lib-es/network/explorer/none.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +15 -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/index.d.ts +5 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +7 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/network/node/explorerProxy.d.ts +27 -0
- package/lib-es/network/node/explorerProxy.d.ts.map +1 -0
- package/lib-es/network/node/explorerProxy.js +254 -0
- package/lib-es/network/node/explorerProxy.js.map +1 -0
- package/lib-es/network/node/index.d.ts +2 -1
- package/lib-es/network/node/index.d.ts.map +1 -1
- package/lib-es/network/node/index.js +11 -10
- package/lib-es/network/node/index.js.map +1 -1
- package/lib-es/network/node/ledger.js +1 -1
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +2 -2
- package/lib-es/network/node/rpc.common.js +3 -3
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/withNodeSources.d.ts +21 -0
- package/lib-es/network/node/withNodeSources.d.ts.map +1 -0
- package/lib-es/network/node/withNodeSources.js +74 -0
- package/lib-es/network/node/withNodeSources.js.map +1 -0
- package/lib-es/nodeSources.d.ts +15 -0
- package/lib-es/nodeSources.d.ts.map +1 -0
- package/lib-es/nodeSources.js +28 -0
- package/lib-es/nodeSources.js.map +1 -0
- package/lib-es/staking/contracts.js +1 -1
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/fetchers.js +1 -1
- package/lib-es/staking/fetchers.js.map +1 -1
- package/lib-es/staking/operations/sei.js +1 -1
- package/lib-es/staking/operations/sei.js.map +1 -1
- package/lib-es/staking/prepareIntents.js +1 -1
- package/lib-es/staking/prepareIntents.js.map +1 -1
- package/lib-es/staking/rewards.js +1 -1
- package/lib-es/staking/rewards.js.map +1 -1
- package/lib-es/staking/transactionData.js +1 -1
- package/lib-es/staking/transactionData.js.map +1 -1
- package/lib-es/staking/utils.d.ts +45 -0
- package/lib-es/staking/utils.d.ts.map +1 -0
- package/lib-es/{utils.js → staking/utils.js} +1 -147
- package/lib-es/staking/utils.js.map +1 -0
- package/lib-es/staking/validators/sei.js +1 -1
- package/lib-es/staking/validators/sei.js.map +1 -1
- package/lib-es/types/staking.d.ts +2 -2
- package/package.json +72 -7
- package/src/adapters/blockOperations.ts +1 -1
- package/src/adapters/etherscan.ts +1 -1
- package/src/adapters/ledger.ts +1 -1
- package/src/api/index.monad_testnet.integ.test.ts +95 -4
- package/src/api/index.ts +2 -2
- package/src/config.ts +22 -34
- package/src/errors.ts +13 -0
- package/src/fixtures/context.fixtures.ts +6 -1
- package/src/logic/broadcast.ts +1 -1
- package/src/logic/common.ts +4 -2
- package/src/logic/craftTransaction.ts +2 -1
- package/src/logic/estimateFees.ts +20 -6
- package/src/logic/getBalance.ts +72 -26
- package/src/logic/getBlock.ts +26 -14
- package/src/logic/getBlockInfo.ts +1 -1
- package/src/logic/getNextSequence.ts +4 -1
- package/src/logic/index.ts +4 -0
- package/src/logic/lastBlock.ts +1 -1
- package/src/logic/listOperations.ts +14 -1
- package/src/logic/tests/broadcast.integ.test.ts +53 -0
- package/src/logic/{broadcast.test.ts → tests/broadcast.test.ts} +7 -7
- package/src/logic/{broadcastSource.test.ts → tests/broadcastSource.test.ts} +6 -6
- package/src/logic/{combine.test.ts → tests/combine.test.ts} +1 -1
- package/src/logic/{common.test.ts → tests/common.test.ts} +45 -21
- package/src/logic/{computeGasLimit.test.ts → tests/computeGasLimit.test.ts} +2 -2
- package/src/logic/{craftTransaction.test.ts → tests/craftTransaction.test.ts} +7 -7
- package/src/logic/{craftTransactionData.test.ts → tests/craftTransactionData.test.ts} +4 -4
- package/src/logic/{estimateFees.test.ts → tests/estimateFees.test.ts} +12 -12
- package/src/logic/tests/getBalance.test.ts +602 -0
- package/src/logic/{getBlock.test.ts → tests/getBlock.test.ts} +182 -89
- package/src/logic/{getBlockInfo.test.ts → tests/getBlockInfo.test.ts} +8 -8
- package/src/logic/{getErc20Data.test.ts → tests/getErc20Data.test.ts} +1 -1
- package/src/logic/{getNextSequence.test.ts → tests/getNextSequence.test.ts} +7 -7
- package/src/logic/{getStakes.test.ts → tests/getStakes.test.ts} +13 -13
- package/src/logic/{internalTransactionsFetcher.test.ts → tests/internalTransactionsFetcher.test.ts} +8 -8
- package/src/logic/{lastBlock.test.ts → tests/lastBlock.test.ts} +7 -7
- package/src/logic/{listOperations.test.ts → tests/listOperations.test.ts} +125 -6
- package/src/logic/{validateAddress.test.ts → tests/validateAddress.test.ts} +1 -1
- package/src/logic/{validateIntent.test.ts → tests/validateIntent.test.ts} +80 -78
- package/src/logic/validateIntent.ts +7 -4
- package/src/logic-public/index.ts +18 -0
- package/src/{utils.test.ts → logic-public/tests/utils.test.ts} +1 -27
- package/src/logic-public/utils.ts +184 -0
- package/src/logic.test.ts +5 -59
- package/src/logic.ts +5 -3
- package/src/network/explorer/etherscan.test.ts +403 -195
- package/src/network/explorer/etherscan.ts +99 -10
- package/src/network/explorer/index.test.ts +27 -0
- package/src/network/explorer/ledger.test.ts +791 -62
- package/src/network/explorer/ledger.ts +426 -54
- package/src/network/explorer/none.ts +3 -0
- package/src/network/explorer/types.ts +29 -5
- package/src/network/index.ts +7 -0
- package/src/network/node/explorerProxy.test.ts +673 -0
- package/src/network/node/explorerProxy.ts +308 -0
- package/src/network/node/index.memoization.test.ts +22 -10
- package/src/network/node/index.test.ts +6 -3
- package/src/network/node/index.ts +11 -7
- package/src/network/node/ledger.ts +1 -1
- package/src/network/node/rpc.common.ts +3 -3
- package/src/network/node/rpc.test.ts +66 -105
- package/src/network/node/withNodeSources.test.ts +240 -0
- package/src/network/node/withNodeSources.ts +95 -0
- package/src/nodeSources.ts +38 -0
- package/src/staking/contracts.ts +1 -1
- package/src/staking/encoder.test.ts +1 -1
- package/src/staking/fetchers.ts +1 -1
- package/src/staking/operations/sei.ts +1 -1
- package/src/staking/prepareIntents.ts +1 -1
- package/src/staking/redelegations.test.ts +1 -1
- package/src/staking/rewards.test.ts +1 -1
- package/src/staking/rewards.ts +1 -1
- package/src/staking/transactionData.ts +1 -1
- package/src/staking/unbondings.test.ts +1 -1
- package/src/staking/utils.test.ts +25 -0
- package/src/{utils.ts → staking/utils.ts} +2 -182
- package/src/staking/validators/sei.ts +1 -1
- package/src/types/staking.ts +2 -2
- package/lib/constants.d.ts +0 -2
- package/lib/constants.d.ts.map +0 -1
- package/lib/constants.js +0 -11
- package/lib/constants.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
- package/lib-es/constants.d.ts +0 -2
- package/lib-es/constants.d.ts.map +0 -1
- package/lib-es/constants.js +0 -7
- package/lib-es/constants.js.map +0 -1
- package/lib-es/utils.d.ts.map +0 -1
- package/lib-es/utils.js.map +0 -1
- package/src/constants.ts +0 -9
- package/src/logic/broadcast.integ.test.ts +0 -46
- package/src/logic/getBalance.test.ts +0 -362
|
@@ -10,7 +10,12 @@ import type {
|
|
|
10
10
|
EtherscanOperation,
|
|
11
11
|
} from '../../types'
|
|
12
12
|
import type { ExplorerApi } from './types'
|
|
13
|
-
import type {
|
|
13
|
+
import type {
|
|
14
|
+
AssetInfo,
|
|
15
|
+
MemoNotSupported,
|
|
16
|
+
Operation,
|
|
17
|
+
} from '@ledgerhq/coin-module-framework/api/types'
|
|
18
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
14
19
|
import type { AxiosRequestConfig } from 'axios'
|
|
15
20
|
import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
16
21
|
import { makeLRUCache } from '@ledgerhq/live-network/cache'
|
|
@@ -39,6 +44,11 @@ import { isEtherscanLikeExplorerConfig } from './types'
|
|
|
39
44
|
export const ETHERSCAN_TIMEOUT = 5000 // 5 seconds between 2 calls
|
|
40
45
|
export const DEFAULT_RETRIES_API = 8
|
|
41
46
|
|
|
47
|
+
// Default upper bound on the extra pages `exhaustEndpoint` fetches to drain a boundary block,
|
|
48
|
+
// overridable per network with `explorer.maxBoundaryExhaustionPages`. Without it, an endpoint
|
|
49
|
+
// that keeps returning full pages of rows the adapter drops never terminates.
|
|
50
|
+
export const DEFAULT_MAX_BOUNDARY_EXHAUSTION_PAGES = 10
|
|
51
|
+
|
|
42
52
|
function getConfiguredMaxLimit(config: EvmConfigInfo): number | undefined {
|
|
43
53
|
const { explorer } = config || {}
|
|
44
54
|
if (!isEtherscanLikeExplorerConfig(explorer)) return undefined
|
|
@@ -48,6 +58,16 @@ function getConfiguredMaxLimit(config: EvmConfigInfo): number | undefined {
|
|
|
48
58
|
return flooredCap >= 1 ? flooredCap : undefined
|
|
49
59
|
}
|
|
50
60
|
|
|
61
|
+
function getMaxBoundaryExhaustionPages(config: EvmConfigInfo): number {
|
|
62
|
+
const { explorer } = config || {}
|
|
63
|
+
const configured = isEtherscanLikeExplorerConfig(explorer)
|
|
64
|
+
? explorer.maxBoundaryExhaustionPages
|
|
65
|
+
: undefined
|
|
66
|
+
return configured !== undefined && configured >= 0
|
|
67
|
+
? Math.floor(configured)
|
|
68
|
+
: DEFAULT_MAX_BOUNDARY_EXHAUSTION_PAGES
|
|
69
|
+
}
|
|
70
|
+
|
|
51
71
|
/**
|
|
52
72
|
* Common parameters for fetching operations from an endpoint
|
|
53
73
|
*/
|
|
@@ -643,9 +663,11 @@ export type FetchOperations = (params: FetchOperationsParams) => Promise<Endpoin
|
|
|
643
663
|
*/
|
|
644
664
|
export async function exhaustEndpoint(
|
|
645
665
|
fetchOperations: FetchOperations,
|
|
646
|
-
params: FetchOperationsParams
|
|
666
|
+
params: FetchOperationsParams,
|
|
667
|
+
logger: Logger
|
|
647
668
|
): Promise<EndpointResult> {
|
|
648
669
|
const { limit } = params
|
|
670
|
+
const maxExtraPages = getMaxBoundaryExhaustionPages(params.config)
|
|
649
671
|
const fetchPage = (
|
|
650
672
|
page: number,
|
|
651
673
|
limitOverride: number | undefined = limit
|
|
@@ -672,6 +694,14 @@ export async function exhaustEndpoint(
|
|
|
672
694
|
return { ...firstPage, isPageFull: isPageFull(limit, firstPage.operations.length) }
|
|
673
695
|
}
|
|
674
696
|
|
|
697
|
+
// A page whose raw rows are all dropped by the adapter (for `txlistinternal`, every
|
|
698
|
+
// `delegatecall` / `staticcall` / `callcode` row) yields no operations, so `boundBlock` is 0.
|
|
699
|
+
// There is no boundary block to drain: the loop below would filter every later page against
|
|
700
|
+
// block 0 and could only ever collect nothing. Stop and let the caller paginate.
|
|
701
|
+
if (firstPage.operations.length === 0) {
|
|
702
|
+
return firstPage
|
|
703
|
+
}
|
|
704
|
+
|
|
675
705
|
// this is an optimization to avoid fetching the next page if the last 2 ops are not at the same block height (most likely case)
|
|
676
706
|
// if the last 2 ops are at the same block height, we need to fetch the next pages
|
|
677
707
|
// otherwise we can stop here (no heights spreading across pages)
|
|
@@ -700,12 +730,23 @@ export async function exhaustEndpoint(
|
|
|
700
730
|
)
|
|
701
731
|
allOperations.push(...boundaryOps)
|
|
702
732
|
// Continue while all ops are at boundary block AND page is full (more pages might exist)
|
|
733
|
+
// `boundaryOps.length === nextPage.operations.length` also holds when a page adapts to no
|
|
734
|
+
// operations at all, which says nothing about the boundary block — hence the page budget.
|
|
703
735
|
} while (
|
|
704
736
|
boundaryOps.length === nextPage.operations.length &&
|
|
705
737
|
nextPage.isPageFull &&
|
|
706
|
-
!nextPage.isDone
|
|
738
|
+
!nextPage.isDone &&
|
|
739
|
+
currentPageNumber <= maxExtraPages
|
|
707
740
|
)
|
|
708
741
|
|
|
742
|
+
if (currentPageNumber > maxExtraPages) {
|
|
743
|
+
logger(
|
|
744
|
+
'warn',
|
|
745
|
+
'EVM getOperations: boundary block exhaustion hit the page budget, some operations at this height may be missing',
|
|
746
|
+
{ boundBlock: firstPage.boundBlock, pages: currentPageNumber, limit }
|
|
747
|
+
)
|
|
748
|
+
}
|
|
749
|
+
|
|
709
750
|
// isDone = false if we found ops at other blocks (more to fetch), otherwise use last page's status
|
|
710
751
|
const hasOpsAtOtherBlocks = boundaryOps.length < nextPage.operations.length
|
|
711
752
|
const resultIsDone = hasOpsAtOtherBlocks ? false : nextPage.isDone
|
|
@@ -736,10 +777,11 @@ export const getOperations = makeLRUCache<
|
|
|
736
777
|
currencyId: string,
|
|
737
778
|
address: string,
|
|
738
779
|
fromBlock: number,
|
|
739
|
-
toBlock
|
|
740
|
-
pagingToken
|
|
741
|
-
limit
|
|
742
|
-
order
|
|
780
|
+
toBlock: number | undefined,
|
|
781
|
+
pagingToken: string | undefined,
|
|
782
|
+
limit: number | undefined,
|
|
783
|
+
order: 'asc' | 'desc' | undefined,
|
|
784
|
+
logger: Logger,
|
|
743
785
|
],
|
|
744
786
|
{
|
|
745
787
|
lastCoinOperations: Array<Operation<MemoNotSupported>>
|
|
@@ -749,7 +791,17 @@ export const getOperations = makeLRUCache<
|
|
|
749
791
|
nextPagingToken: string
|
|
750
792
|
}
|
|
751
793
|
>(
|
|
752
|
-
async (
|
|
794
|
+
async (
|
|
795
|
+
config,
|
|
796
|
+
currencyId,
|
|
797
|
+
address,
|
|
798
|
+
fromBlock,
|
|
799
|
+
toBlock,
|
|
800
|
+
pagingToken,
|
|
801
|
+
limit,
|
|
802
|
+
order = 'desc',
|
|
803
|
+
logger
|
|
804
|
+
) => {
|
|
753
805
|
try {
|
|
754
806
|
const configuredMaxLimit = getConfiguredMaxLimit(config)
|
|
755
807
|
const effectiveLimit =
|
|
@@ -803,7 +855,7 @@ export const getOperations = makeLRUCache<
|
|
|
803
855
|
fromBlock: effectiveFromBlock,
|
|
804
856
|
...(effectiveToBlock !== undefined && { toBlock: effectiveToBlock }),
|
|
805
857
|
}
|
|
806
|
-
const result = await exhaustEndpoint(endpoint, params)
|
|
858
|
+
const result = await exhaustEndpoint(endpoint, params, logger)
|
|
807
859
|
const effectiveBoundBlock = computeEffectiveBoundBlock(
|
|
808
860
|
effectiveLimit,
|
|
809
861
|
boundBlock,
|
|
@@ -888,7 +940,7 @@ export const getOperations = makeLRUCache<
|
|
|
888
940
|
}
|
|
889
941
|
} catch (err) {
|
|
890
942
|
if (err instanceof RateLimitError) throw err
|
|
891
|
-
|
|
943
|
+
logger('EVM getOperations', 'Error while fetching data from Etherscan like API', err)
|
|
892
944
|
const message =
|
|
893
945
|
typeof err === 'string'
|
|
894
946
|
? err
|
|
@@ -911,12 +963,49 @@ export const getOperations = makeLRUCache<
|
|
|
911
963
|
{ ttl: ETHERSCAN_TIMEOUT }
|
|
912
964
|
)
|
|
913
965
|
|
|
966
|
+
/**
|
|
967
|
+
* Discover which tokens an address holds through the dedicated ERC20 endpoint alone (`tokentx`,
|
|
968
|
+
* or the corescan equivalent), rather than through the full `getOperations` wrapper.
|
|
969
|
+
*
|
|
970
|
+
* `getBalance` only ever reads `lastTokenOperations` from `getOperations`'s result, and with
|
|
971
|
+
* `limit === undefined` (what a discovery call passes) `exhaustEndpoint` performs exactly one
|
|
972
|
+
* unbounded request per endpoint with no cross-endpoint bound in effect — so calling
|
|
973
|
+
* `getTokenOperations` alone yields the same asset references, while sparing the coin, internal
|
|
974
|
+
* and NFT endpoints, which this arm never needed to discover tokens.
|
|
975
|
+
*/
|
|
976
|
+
export const discoverTokenAssets = makeLRUCache<
|
|
977
|
+
[config: EvmConfigInfo, currencyId: string, address: string, fromBlock?: number],
|
|
978
|
+
AssetInfo[]
|
|
979
|
+
>(
|
|
980
|
+
async (config, currencyId, address, fromBlock = 0) => {
|
|
981
|
+
const { operations } = await getTokenOperations({
|
|
982
|
+
currencyId,
|
|
983
|
+
config,
|
|
984
|
+
address,
|
|
985
|
+
fromBlock,
|
|
986
|
+
sort: 'desc',
|
|
987
|
+
})
|
|
988
|
+
|
|
989
|
+
const assets = new Map<string, AssetInfo>()
|
|
990
|
+
for (const operation of operations) {
|
|
991
|
+
if (!('assetReference' in operation.asset) || !operation.asset.assetReference) continue
|
|
992
|
+
assets.set(operation.asset.assetReference, operation.asset)
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
return Array.from(assets.values())
|
|
996
|
+
},
|
|
997
|
+
(_config, currencyId, address, fromBlock) => `${currencyId}:${address}:${fromBlock ?? 0}`,
|
|
998
|
+
{ ttl: ETHERSCAN_TIMEOUT }
|
|
999
|
+
)
|
|
1000
|
+
|
|
914
1001
|
const explorerApi: ExplorerApi = {
|
|
915
1002
|
getOperations,
|
|
1003
|
+
discoverTokenAssets,
|
|
916
1004
|
}
|
|
917
1005
|
|
|
918
1006
|
const explorerApiNoCache: ExplorerApi = {
|
|
919
1007
|
getOperations: getOperations.force,
|
|
1008
|
+
discoverTokenAssets: discoverTokenAssets.force,
|
|
920
1009
|
}
|
|
921
1010
|
|
|
922
1011
|
export default { explorerApi, explorerApiNoCache }
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from '../../fixtures/context.fixtures'
|
|
13
13
|
import etherscanLikeApi from './etherscan'
|
|
14
14
|
import ledgerExplorerApi from './ledger'
|
|
15
|
+
import noExplorerAPI from './none'
|
|
15
16
|
import { getExplorerApi } from './index'
|
|
16
17
|
|
|
17
18
|
const configFor = (currencyId: string): EvmConfigInfo => {
|
|
@@ -54,6 +55,8 @@ const configFor = (currencyId: string): EvmConfigInfo => {
|
|
|
54
55
|
node,
|
|
55
56
|
explorer: mkLedgerExplorer({ explorerId: 'eth' }),
|
|
56
57
|
})
|
|
58
|
+
case 'none-coin':
|
|
59
|
+
return createMockEvmConfigInfo({ chainId: 1, node, explorer: { type: 'none' } })
|
|
57
60
|
default:
|
|
58
61
|
return createMockEvmConfigInfo({ chainId: 1, node })
|
|
59
62
|
}
|
|
@@ -101,6 +104,30 @@ describe('EVM Family', () => {
|
|
|
101
104
|
|
|
102
105
|
expect(explorerA).toBe(ledgerExplorerApi)
|
|
103
106
|
})
|
|
107
|
+
|
|
108
|
+
it('should return the none api', () => {
|
|
109
|
+
const explorerA = getExplorerApi(configFor('none-coin'), 'none-coin')
|
|
110
|
+
|
|
111
|
+
expect(explorerA).toBe(noExplorerAPI)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it.each([
|
|
115
|
+
['etherscan', 'etherscan-coin'],
|
|
116
|
+
['ledger', 'ledger-coin'],
|
|
117
|
+
['none', 'none-coin'],
|
|
118
|
+
])('%s arm exposes discoverTokenAssets', (_type, currencyId) => {
|
|
119
|
+
const explorer = getExplorerApi(configFor(currencyId), currencyId)
|
|
120
|
+
|
|
121
|
+
expect(typeof explorer.discoverTokenAssets).toBe('function')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('the none arm resolves discoverTokenAssets to an empty array', async () => {
|
|
125
|
+
const explorer = getExplorerApi(configFor('none-coin'), 'none-coin')
|
|
126
|
+
|
|
127
|
+
await expect(
|
|
128
|
+
explorer.discoverTokenAssets(configFor('none-coin'), 'none-coin', '0xaddress')
|
|
129
|
+
).resolves.toEqual([])
|
|
130
|
+
})
|
|
104
131
|
})
|
|
105
132
|
})
|
|
106
133
|
})
|