@ledgerhq/coin-evm 9.0.1 → 10.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/.oxlintrc.json +2 -6
- package/CHANGELOG.md +18 -0
- package/lib/abis/index.d.ts +8 -0
- package/lib/abis/index.d.ts.map +1 -1
- package/lib/abis/index.js +30 -0
- package/lib/abis/index.js.map +1 -1
- package/lib/adapters/blockOperations.js +2 -2
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +2 -1
- package/lib/api/index.js.map +1 -1
- package/lib/internalTxSources.d.ts.map +1 -1
- package/lib/internalTxSources.js +21 -3
- package/lib/internalTxSources.js.map +1 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js +11 -3
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +4 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +4 -2
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.js +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js +2 -2
- 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/predicates.d.ts +17 -0
- package/lib/logic/predicates.d.ts.map +1 -0
- package/lib/logic/predicates.js +126 -0
- package/lib/logic/predicates.js.map +1 -0
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js +4 -6
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/network/explorer/index.d.ts +1 -1
- package/lib/network/explorer/index.d.ts.map +1 -1
- package/lib/network/explorer/index.js +2 -2
- package/lib/network/explorer/index.js.map +1 -1
- package/lib/network/explorer/ledger.js +3 -3
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/explorer/types.js +11 -1
- package/lib/network/explorer/types.js.map +1 -1
- package/lib/network/gasTracker/ledger.d.ts +1 -2
- package/lib/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib/network/gasTracker/ledger.js +3 -5
- package/lib/network/gasTracker/ledger.js.map +1 -1
- package/lib/network/gasTracker/types.d.ts +1 -2
- package/lib/network/gasTracker/types.d.ts.map +1 -1
- package/lib/network/gasTracker/types.js.map +1 -1
- package/lib/network/node/explorerProxy.d.ts.map +1 -1
- package/lib/network/node/explorerProxy.js +10 -5
- package/lib/network/node/explorerProxy.js.map +1 -1
- package/lib/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
- package/lib/network/node/gethCallTracerToTraceBlockItems.js +10 -12
- package/lib/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
- package/lib/network/node/index.js +1 -1
- package/lib/network/node/index.js.map +1 -1
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js +11 -7
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +60 -70
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +6 -7
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/network/node/types.js +0 -27
- package/lib/network/node/types.js.map +1 -1
- package/lib/nodeSources.d.ts.map +1 -1
- package/lib/nodeSources.js +11 -3
- package/lib/nodeSources.js.map +1 -1
- package/lib/staking/contracts.d.ts.map +1 -1
- package/lib/staking/contracts.js +1 -3
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/detectOperationType.d.ts +0 -3
- package/lib/staking/detectOperationType.d.ts.map +1 -1
- package/lib/staking/detectOperationType.js +15 -14
- package/lib/staking/detectOperationType.js.map +1 -1
- package/lib/staking/fetchers.d.ts.map +1 -1
- package/lib/staking/fetchers.js +2 -3
- package/lib/staking/fetchers.js.map +1 -1
- package/lib/staking/operations/index.d.ts.map +1 -1
- package/lib/staking/operations/index.js +18 -1
- package/lib/staking/operations/index.js.map +1 -1
- package/lib/staking/prepareIntents.d.ts.map +1 -1
- package/lib/staking/prepareIntents.js +4 -3
- package/lib/staking/prepareIntents.js.map +1 -1
- package/lib/staking/redelegations.d.ts.map +1 -1
- package/lib/staking/redelegations.js +4 -7
- package/lib/staking/redelegations.js.map +1 -1
- package/lib/staking/unbondings.d.ts.map +1 -1
- package/lib/staking/unbondings.js +3 -4
- package/lib/staking/unbondings.js.map +1 -1
- package/lib/staking/utils.d.ts.map +1 -1
- package/lib/staking/utils.js +22 -27
- package/lib/staking/utils.js.map +1 -1
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js +16 -8
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib/staking/validators/monadResolver.js +4 -3
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib/staking/validators/somnia.js +5 -5
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/zero_gravity.js +5 -5
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/abis/index.d.ts +8 -0
- package/lib-es/abis/index.d.ts.map +1 -1
- package/lib-es/abis/index.js +29 -0
- package/lib-es/abis/index.js.map +1 -1
- package/lib-es/adapters/blockOperations.js +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +2 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/internalTxSources.d.ts.map +1 -1
- package/lib-es/internalTxSources.js +21 -3
- package/lib-es/internalTxSources.js.map +1 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +11 -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 +4 -1
- 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 +4 -2
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.js +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js +2 -2
- 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/predicates.d.ts +17 -0
- package/lib-es/logic/predicates.d.ts.map +1 -0
- package/lib-es/logic/predicates.js +114 -0
- package/lib-es/logic/predicates.js.map +1 -0
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js +4 -6
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/network/explorer/index.d.ts +1 -1
- package/lib-es/network/explorer/index.d.ts.map +1 -1
- package/lib-es/network/explorer/index.js +2 -2
- package/lib-es/network/explorer/index.js.map +1 -1
- package/lib-es/network/explorer/ledger.js +3 -3
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/explorer/types.js +11 -1
- package/lib-es/network/explorer/types.js.map +1 -1
- package/lib-es/network/gasTracker/ledger.d.ts +1 -2
- package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib-es/network/gasTracker/ledger.js +3 -5
- package/lib-es/network/gasTracker/ledger.js.map +1 -1
- package/lib-es/network/gasTracker/types.d.ts +1 -2
- package/lib-es/network/gasTracker/types.d.ts.map +1 -1
- package/lib-es/network/gasTracker/types.js.map +1 -1
- package/lib-es/network/node/explorerProxy.d.ts.map +1 -1
- package/lib-es/network/node/explorerProxy.js +10 -5
- package/lib-es/network/node/explorerProxy.js.map +1 -1
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.js +4 -6
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
- package/lib-es/network/node/index.js +1 -1
- package/lib-es/network/node/index.js.map +1 -1
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js +11 -7
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +58 -68
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +6 -7
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/network/node/types.js +0 -25
- package/lib-es/network/node/types.js.map +1 -1
- package/lib-es/nodeSources.d.ts.map +1 -1
- package/lib-es/nodeSources.js +11 -3
- package/lib-es/nodeSources.js.map +1 -1
- package/lib-es/staking/contracts.d.ts.map +1 -1
- package/lib-es/staking/contracts.js +1 -3
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/detectOperationType.d.ts +0 -3
- package/lib-es/staking/detectOperationType.d.ts.map +1 -1
- package/lib-es/staking/detectOperationType.js +15 -14
- package/lib-es/staking/detectOperationType.js.map +1 -1
- package/lib-es/staking/fetchers.d.ts.map +1 -1
- package/lib-es/staking/fetchers.js +2 -3
- package/lib-es/staking/fetchers.js.map +1 -1
- package/lib-es/staking/operations/index.d.ts.map +1 -1
- package/lib-es/staking/operations/index.js +18 -1
- package/lib-es/staking/operations/index.js.map +1 -1
- package/lib-es/staking/prepareIntents.d.ts.map +1 -1
- package/lib-es/staking/prepareIntents.js +2 -1
- package/lib-es/staking/prepareIntents.js.map +1 -1
- package/lib-es/staking/redelegations.d.ts.map +1 -1
- package/lib-es/staking/redelegations.js +1 -4
- package/lib-es/staking/redelegations.js.map +1 -1
- package/lib-es/staking/unbondings.d.ts.map +1 -1
- package/lib-es/staking/unbondings.js +3 -4
- package/lib-es/staking/unbondings.js.map +1 -1
- package/lib-es/staking/utils.d.ts.map +1 -1
- package/lib-es/staking/utils.js +20 -25
- package/lib-es/staking/utils.js.map +1 -1
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js +13 -5
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib-es/staking/validators/monadResolver.js +2 -1
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/staking/validators/somnia.js +3 -3
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js +3 -3
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/package.json +2 -2
- package/src/abis/index.test.ts +36 -0
- package/src/abis/index.ts +30 -0
- package/src/adapters/blockOperations.ts +1 -1
- package/src/api/index.cronos.integ.test.ts +28 -0
- package/src/api/index.integ.test.ts +57 -94
- package/src/api/index.ts +3 -2
- package/src/internalTxSources.ts +20 -3
- package/src/logic/common.ts +13 -3
- package/src/logic/craftTransaction.ts +4 -2
- package/src/logic/estimateFees.ts +4 -3
- package/src/logic/getBalance.ts +1 -1
- package/src/logic/internalTransactionsFetcher.ts +2 -2
- package/src/logic/listOperations.ts +1 -1
- package/src/logic/predicates.ts +124 -0
- package/src/logic/tests/craftTransaction.test.ts +1 -1
- package/src/logic/tests/getStakes.test.ts +1 -0
- package/src/logic/tests/validateIntent.test.ts +4 -1
- package/src/logic/validateIntent.ts +2 -6
- package/src/network/explorer/index.test.ts +9 -16
- package/src/network/explorer/index.ts +2 -2
- package/src/network/explorer/ledger.test.ts +21 -15
- package/src/network/explorer/ledger.ts +3 -3
- package/src/network/explorer/types.ts +12 -3
- package/src/network/gasTracker/ledger.test.ts +0 -10
- package/src/network/gasTracker/ledger.ts +2 -7
- package/src/network/gasTracker/types.ts +0 -2
- package/src/network/node/explorerProxy.ts +11 -8
- package/src/network/node/gethCallTracerToTraceBlockItems.test.ts +1 -1
- package/src/network/node/gethCallTracerToTraceBlockItems.ts +6 -9
- package/src/network/node/index.ts +1 -1
- package/src/network/node/ledger.ts +15 -12
- package/src/network/node/rpc.common.ts +92 -88
- package/src/network/node/rpc.test.ts +119 -0
- package/src/network/node/types.ts +6 -35
- package/src/nodeSources.ts +11 -3
- package/src/staking/contracts.ts +1 -3
- package/src/staking/detectOperationType.ts +15 -14
- package/src/staking/fetchers.ts +2 -3
- package/src/staking/operations/index.test.ts +1 -0
- package/src/staking/operations/index.ts +26 -7
- package/src/staking/prepareIntents.ts +2 -1
- package/src/staking/redelegations.ts +1 -5
- package/src/staking/unbondings.ts +2 -4
- package/src/staking/utils.ts +19 -26
- package/src/staking/validators/monad.test.ts +6 -4
- package/src/staking/validators/monad.ts +12 -5
- package/src/staking/validators/monadResolver.ts +2 -1
- package/src/staking/validators/somnia.test.ts +1 -0
- package/src/staking/validators/somnia.ts +5 -5
- package/src/staking/validators/zero_gravity.test.ts +1 -0
- package/src/staking/validators/zero_gravity.ts +3 -3
- package/lib/logic/evmUnit.d.ts +0 -3
- package/lib/logic/evmUnit.d.ts.map +0 -1
- package/lib/logic/evmUnit.js +0 -94
- package/lib/logic/evmUnit.js.map +0 -1
- package/lib-es/logic/evmUnit.d.ts +0 -3
- package/lib-es/logic/evmUnit.d.ts.map +0 -1
- package/lib-es/logic/evmUnit.js +0 -91
- package/lib-es/logic/evmUnit.js.map +0 -1
- package/src/logic/evmUnit.ts +0 -93
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-evm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Ledger EVM Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"license": "Apache-2.0",
|
|
113
113
|
"dependencies": {
|
|
114
114
|
"@ethersproject/shims": "^5.7.0",
|
|
115
|
-
"axios": "1.
|
|
115
|
+
"axios": "1.20.0",
|
|
116
116
|
"bignumber.js": "^9.1.2",
|
|
117
117
|
"eip55": "^2.1.1",
|
|
118
118
|
"ethers": "6.15.0",
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Fragment, Interface } from 'ethers'
|
|
5
|
+
import ERC20_ABI from './erc20.abi.json'
|
|
6
|
+
import { toInterfaceAbi } from './index'
|
|
7
|
+
|
|
8
|
+
describe('toInterfaceAbi', () => {
|
|
9
|
+
it('parses every JSON ABI entry into a Fragment', () => {
|
|
10
|
+
const abi = toInterfaceAbi(ERC20_ABI)
|
|
11
|
+
|
|
12
|
+
expect(Array.isArray(abi)).toBe(true)
|
|
13
|
+
if (!Array.isArray(abi)) return
|
|
14
|
+
expect(abi).toHaveLength(ERC20_ABI.length)
|
|
15
|
+
expect(abi.every((entry) => entry instanceof Fragment)).toBe(true)
|
|
16
|
+
expect(new Interface(abi).getFunction('transfer')?.name).toBe('transfer')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('parses a JSON ABI string and human-readable fragments', () => {
|
|
20
|
+
const fromJson = toInterfaceAbi(JSON.stringify(ERC20_ABI))
|
|
21
|
+
const fromSignature = toInterfaceAbi(['function balanceOf(address) view returns (uint256)'])
|
|
22
|
+
|
|
23
|
+
expect(new Interface(fromJson).getFunction('approve')?.name).toBe('approve')
|
|
24
|
+
expect(new Interface(fromSignature).getFunction('balanceOf')?.name).toBe('balanceOf')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it.each([
|
|
28
|
+
['a number', 42],
|
|
29
|
+
['a plain object', { type: 'function', name: 'foo' }],
|
|
30
|
+
['invalid JSON', '{'],
|
|
31
|
+
['an entry that is not a fragment', [42]],
|
|
32
|
+
['a null entry', [null]],
|
|
33
|
+
])('rejects %s', (_label, value) => {
|
|
34
|
+
expect(() => toInterfaceAbi(value)).toThrow('invalid contract ABI')
|
|
35
|
+
})
|
|
36
|
+
})
|
package/src/abis/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { InterfaceAbi } from 'ethers'
|
|
5
|
+
import { Fragment } from 'ethers'
|
|
4
6
|
import ERC20_ABI from './erc20.abi.json'
|
|
5
7
|
import ERC721_ABI from './erc721.abi.json'
|
|
6
8
|
import ERC1155_ABI from './erc1155.abi.json'
|
|
@@ -14,3 +16,31 @@ export {
|
|
|
14
16
|
OPTIMISM_GAS_PRICE_ORACLE_ABI,
|
|
15
17
|
SCROLL_GAS_PRICE_ORACLE_ABI,
|
|
16
18
|
}
|
|
19
|
+
|
|
20
|
+
function parseAbiJson(value: string): unknown {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(value)
|
|
23
|
+
} catch {
|
|
24
|
+
throw new Error('invalid contract ABI')
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function parseAbiFragment(entry: unknown): Fragment {
|
|
29
|
+
try {
|
|
30
|
+
return Fragment.from(entry)
|
|
31
|
+
} catch {
|
|
32
|
+
throw new Error('invalid contract ABI')
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Parse a contract ABI into {@link Fragment} instances.
|
|
38
|
+
*
|
|
39
|
+
* `Array.isArray` only narrows to `any[]`, so each entry is parsed before the
|
|
40
|
+
* value is returned as an `InterfaceAbi`.
|
|
41
|
+
*/
|
|
42
|
+
export function toInterfaceAbi(value: unknown): InterfaceAbi {
|
|
43
|
+
const entries = typeof value === 'string' ? parseAbiJson(value) : value
|
|
44
|
+
if (!Array.isArray(entries)) throw new Error('invalid contract ABI')
|
|
45
|
+
return entries.map(parseAbiFragment)
|
|
46
|
+
}
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
} from '@ledgerhq/coin-module-framework/api/index'
|
|
11
11
|
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
12
12
|
import { safeEncodeEIP55 } from '../logic-public'
|
|
13
|
-
import { isTraceBlockCallAction } from '../
|
|
13
|
+
import { isTraceBlockCallAction } from '../logic/predicates'
|
|
14
14
|
import { NON_VALUE_TRANSFER_CALL_TYPES } from './nonValueTransferCallTypes'
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -24,6 +24,34 @@ describe('EVM Cronos Network (blockscout explorer)', () => {
|
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
describe('listOperations', () => {
|
|
27
|
+
/**
|
|
28
|
+
* FIXME: Cronos's Etherscan-compatible proxy does not honour ascending block-range
|
|
29
|
+
* pagination. Its `txlist` response is descending even with `sort=asc`; after the first
|
|
30
|
+
* cursor (`74012601-0001`), the next request starts at 74013395, so block 61849051 is
|
|
31
|
+
* skipped forever. This is intentionally opt-in (`*.integ.test.ts`) and skipped: unskip it
|
|
32
|
+
* when the explorer is repaired to verify that the pinned historical operation is reachable.
|
|
33
|
+
*/
|
|
34
|
+
it.skip('FIXME: reaches the pinned historical operation when paging from genesis', async () => {
|
|
35
|
+
const context = createMockEvmContext(config)
|
|
36
|
+
const address = '0x06B68eAFd87Ce84b2c6A47F0e6bfa6074c042Ab9'
|
|
37
|
+
const options = { minHeight: 0, order: 'asc' as const, limit: 200 }
|
|
38
|
+
|
|
39
|
+
const firstPage = await module.listOperations(context, address, options)
|
|
40
|
+
const firstPageHeights = firstPage.items.map((operation) => operation.tx.block.height)
|
|
41
|
+
|
|
42
|
+
// Pinned historical rows returned by the broken first page.
|
|
43
|
+
expect(firstPageHeights).toEqual(expect.arrayContaining([29433129, 74012600]))
|
|
44
|
+
expect(firstPage.next).toBe('74012601-0001')
|
|
45
|
+
|
|
46
|
+
const secondPage = await module.listOperations(context, address, {
|
|
47
|
+
...options,
|
|
48
|
+
cursor: firstPage.next,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// The current proxy instead starts this page at 74013395, bypassing 61849051.
|
|
52
|
+
expect(secondPage.items.map((operation) => operation.tx.block.height)).toContain(61849051)
|
|
53
|
+
})
|
|
54
|
+
|
|
27
55
|
it('paginates with distinct cursors across pages', async () => {
|
|
28
56
|
const page1 = await module.listOperations(
|
|
29
57
|
createMockEvmContext(config),
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { MemoNotSupported } from '@ledgerhq/coin-module-framework/api/index'
|
|
5
|
+
import type { BufferTxData, Operation } from '@ledgerhq/coin-module-framework/api/types'
|
|
6
|
+
import { createStakingTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
|
|
5
7
|
import { ethers } from 'ethers'
|
|
6
8
|
import {
|
|
7
9
|
createMockEvmConfigInfo,
|
|
@@ -19,7 +21,7 @@ describe.each([
|
|
|
19
21
|
'external node and explorer',
|
|
20
22
|
createMockEvmConfigInfo({
|
|
21
23
|
chainId: 1,
|
|
22
|
-
node: mkExternalNode({ uri: 'https://
|
|
24
|
+
node: mkExternalNode({ uri: 'https://gateway.tenderly.co/public/mainnet' }),
|
|
23
25
|
explorer: mkEtherscanExplorer({ uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/1' }),
|
|
24
26
|
supportedTokens: ['erc721', 'erc1155'],
|
|
25
27
|
}),
|
|
@@ -869,7 +871,7 @@ describe('EVM Api: external node and explorer ONLY', () => {
|
|
|
869
871
|
const context = createMockEvmContext(
|
|
870
872
|
createMockEvmConfigInfo({
|
|
871
873
|
chainId: 1,
|
|
872
|
-
node: mkExternalNode({ uri: 'https://
|
|
874
|
+
node: mkExternalNode({ uri: 'https://gateway.tenderly.co/public/mainnet' }),
|
|
873
875
|
explorer: mkEtherscanExplorer({ uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/1' }),
|
|
874
876
|
supportedTokens: ['erc721', 'erc1155'],
|
|
875
877
|
})
|
|
@@ -952,53 +954,6 @@ describe('EVM Api: external node and explorer ONLY', () => {
|
|
|
952
954
|
})
|
|
953
955
|
})
|
|
954
956
|
|
|
955
|
-
describe('EVM Api (Moonbeam Network)', () => {
|
|
956
|
-
let module: ReturnType<typeof createApi>
|
|
957
|
-
const context = createMockEvmContext(
|
|
958
|
-
createMockEvmConfigInfo({
|
|
959
|
-
chainId: 1284,
|
|
960
|
-
node: mkExternalNode({ uri: 'https://moonbeam.coin.ledger.com' }),
|
|
961
|
-
explorer: mkEtherscanExplorer({
|
|
962
|
-
uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/1284',
|
|
963
|
-
}),
|
|
964
|
-
})
|
|
965
|
-
)
|
|
966
|
-
|
|
967
|
-
beforeAll(() => {
|
|
968
|
-
module = createApi('moonbeam')
|
|
969
|
-
})
|
|
970
|
-
|
|
971
|
-
describe('listOperations', () => {
|
|
972
|
-
/**
|
|
973
|
-
* Non-regression: some Moonbeam transactions (e.g. contract creations) have
|
|
974
|
-
* an empty `to` field in the Etherscan API response. The adapter used to emit
|
|
975
|
-
* `recipients: [""]` (array with one empty string) instead of `recipients: []`.
|
|
976
|
-
* @see https://coin-service.api.ledger.com/v1/moonbeam/account/0x2a9c55b6dc56da178f9f9a566f1161237b73ba66/operations?limit=100
|
|
977
|
-
*/
|
|
978
|
-
it('returns no operations with empty string recipients or senders', async () => {
|
|
979
|
-
const { items } = await module.listOperations(
|
|
980
|
-
context,
|
|
981
|
-
'0x2a9c55b6dc56da178f9f9a566f1161237b73ba66',
|
|
982
|
-
{
|
|
983
|
-
minHeight: 0,
|
|
984
|
-
order: 'desc',
|
|
985
|
-
limit: 100,
|
|
986
|
-
}
|
|
987
|
-
)
|
|
988
|
-
|
|
989
|
-
expect(items.length).toBeGreaterThan(0)
|
|
990
|
-
items.forEach((op) => {
|
|
991
|
-
op.recipients.forEach((r) => {
|
|
992
|
-
expect(r).not.toBe('')
|
|
993
|
-
})
|
|
994
|
-
op.senders.forEach((s) => {
|
|
995
|
-
expect(s).not.toBe('')
|
|
996
|
-
})
|
|
997
|
-
})
|
|
998
|
-
})
|
|
999
|
-
})
|
|
1000
|
-
})
|
|
1001
|
-
|
|
1002
957
|
describe('EVM Api (SEI Network)', () => {
|
|
1003
958
|
let module: ReturnType<typeof createApi>
|
|
1004
959
|
const seiStakingSender = '0x66c4371aE8FFeD2ec1c2EBbbcCfb7E494181E1E3'
|
|
@@ -1020,17 +975,19 @@ describe('EVM Api (SEI Network)', () => {
|
|
|
1020
975
|
|
|
1021
976
|
describe('craftTransaction', () => {
|
|
1022
977
|
it('crafts a legacy delegate transaction', async () => {
|
|
1023
|
-
const { transaction: result } = await module.craftTransaction(
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
978
|
+
const { transaction: result } = await module.craftTransaction(
|
|
979
|
+
context,
|
|
980
|
+
createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
981
|
+
type: 'staking-legacy',
|
|
982
|
+
amount: seiStakingDelegationAmount,
|
|
983
|
+
mode: 'delegate',
|
|
984
|
+
sender: seiStakingSender,
|
|
985
|
+
recipient: seiStakingRecipient,
|
|
986
|
+
valAddress: 'seivaloper1ummny4p645xraxc4m7nphf7vxawfzt3p5hn47t',
|
|
987
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
988
|
+
asset: { type: 'native' },
|
|
989
|
+
})
|
|
990
|
+
)
|
|
1034
991
|
|
|
1035
992
|
expect(result).toMatch(/^0x[A-Fa-f0-9]+$/)
|
|
1036
993
|
expect(ethers.Transaction.from(result)).toMatchObject({
|
|
@@ -1044,17 +1001,19 @@ describe('EVM Api (SEI Network)', () => {
|
|
|
1044
1001
|
})
|
|
1045
1002
|
|
|
1046
1003
|
it('crafts an eip1559 delegate transaction', async () => {
|
|
1047
|
-
const { transaction: result } = await module.craftTransaction(
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1004
|
+
const { transaction: result } = await module.craftTransaction(
|
|
1005
|
+
context,
|
|
1006
|
+
createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
1007
|
+
type: 'staking-eip1559',
|
|
1008
|
+
amount: seiStakingDelegationAmount,
|
|
1009
|
+
mode: 'delegate',
|
|
1010
|
+
sender: seiStakingSender,
|
|
1011
|
+
recipient: seiStakingRecipient,
|
|
1012
|
+
valAddress: 'seivaloper1ummny4p645xraxc4m7nphf7vxawfzt3p5hn47t',
|
|
1013
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
1014
|
+
asset: { type: 'native' },
|
|
1015
|
+
})
|
|
1016
|
+
)
|
|
1058
1017
|
|
|
1059
1018
|
expect(result).toMatch(/^0x[A-Fa-f0-9]+$/)
|
|
1060
1019
|
expect(ethers.Transaction.from(result)).toMatchObject({
|
|
@@ -1073,17 +1032,19 @@ describe('EVM Api (SEI Network)', () => {
|
|
|
1073
1032
|
|
|
1074
1033
|
describe('estimateFees', () => {
|
|
1075
1034
|
it('estimates fees for legacy staking delegation', async () => {
|
|
1076
|
-
const result = await module.estimateFees(
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1035
|
+
const result = await module.estimateFees(
|
|
1036
|
+
context,
|
|
1037
|
+
createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
1038
|
+
type: 'staking-legacy',
|
|
1039
|
+
amount: seiStakingDelegationAmount,
|
|
1040
|
+
mode: 'delegate',
|
|
1041
|
+
sender: seiStakingSender,
|
|
1042
|
+
recipient: seiStakingRecipient,
|
|
1043
|
+
valAddress: 'seivaloper1ummny4p645xraxc4m7nphf7vxawfzt3p5hn47t',
|
|
1044
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
1045
|
+
asset: { type: 'native' },
|
|
1046
|
+
})
|
|
1047
|
+
)
|
|
1087
1048
|
|
|
1088
1049
|
expect(result).toEqual({
|
|
1089
1050
|
value: expect.any(BigInt),
|
|
@@ -1101,17 +1062,19 @@ describe('EVM Api (SEI Network)', () => {
|
|
|
1101
1062
|
})
|
|
1102
1063
|
|
|
1103
1064
|
it('estimates fees for eip1559 staking delegation', async () => {
|
|
1104
|
-
const result = await module.estimateFees(
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1065
|
+
const result = await module.estimateFees(
|
|
1066
|
+
context,
|
|
1067
|
+
createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
1068
|
+
type: 'staking-eip1559',
|
|
1069
|
+
amount: seiStakingDelegationAmount,
|
|
1070
|
+
mode: 'delegate',
|
|
1071
|
+
sender: seiStakingSender,
|
|
1072
|
+
recipient: seiStakingRecipient,
|
|
1073
|
+
valAddress: 'seivaloper1ummny4p645xraxc4m7nphf7vxawfzt3p5hn47t',
|
|
1074
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
1075
|
+
asset: { type: 'native' },
|
|
1076
|
+
})
|
|
1077
|
+
)
|
|
1115
1078
|
|
|
1116
1079
|
expect(result).toEqual({
|
|
1117
1080
|
value: expect.any(BigInt),
|
package/src/api/index.ts
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
listOperations,
|
|
39
39
|
validateIntent,
|
|
40
40
|
} from '../logic/index'
|
|
41
|
+
import { isRecord } from '../logic/predicates'
|
|
41
42
|
import { validateAddress } from '../logic/validateAddress'
|
|
42
43
|
import { getNodeApi } from '../network/node'
|
|
43
44
|
import { getValidatorsPage } from '../staking/validators'
|
|
@@ -142,11 +143,11 @@ export function createApi(currencyId: string) {
|
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
export function parseCallParams(params: unknown): EvmCallParams {
|
|
145
|
-
if (
|
|
146
|
+
if (!isRecord(params)) {
|
|
146
147
|
throw new TypeError('Invalid EVM call params: expected an object')
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
const { to, data, block } = params
|
|
150
|
+
const { to, data, block } = params
|
|
150
151
|
if (typeof to !== 'string' || !isHexString(to, 20)) {
|
|
151
152
|
throw new TypeError('Invalid EVM call params: "to" must be a 0x-prefixed 20-byte hex address')
|
|
152
153
|
}
|
package/src/internalTxSources.ts
CHANGED
|
@@ -31,7 +31,8 @@ export function internalTxSourcesFromList(sources: readonly string[]): InternalT
|
|
|
31
31
|
throw new Error('internalTxSources: at least one source is required')
|
|
32
32
|
}
|
|
33
33
|
const seen = new Set<string>()
|
|
34
|
-
|
|
34
|
+
const validated: InternalTxSource[] = []
|
|
35
|
+
for (const [index, source] of sources.entries()) {
|
|
35
36
|
if (!isInternalTxSource(source)) {
|
|
36
37
|
throw new Error(`internalTxSources: invalid source "${source}"`)
|
|
37
38
|
}
|
|
@@ -42,8 +43,24 @@ export function internalTxSourcesFromList(sources: readonly string[]): InternalT
|
|
|
42
43
|
if (seen.has(source)) throw new Error(`internalTxSources: duplicate source "${source}"`)
|
|
43
44
|
seen.add(source)
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
validated.push(source)
|
|
47
|
+
}
|
|
48
|
+
const frozen = Object.freeze(validated)
|
|
49
|
+
if (isInternalTxSourceList(frozen)) return frozen
|
|
50
|
+
throw new Error('internalTxSources: invalid list')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isInternalTxSourceList(
|
|
54
|
+
sources: readonly InternalTxSource[]
|
|
55
|
+
): sources is InternalTxSourceList {
|
|
56
|
+
if (sources.length === 0) return false
|
|
57
|
+
const seen = new Set<string>()
|
|
58
|
+
for (const [index, source] of sources.entries()) {
|
|
59
|
+
if (source === 'empty') return index === sources.length - 1
|
|
60
|
+
if (seen.has(source)) return false
|
|
61
|
+
seen.add(source)
|
|
62
|
+
}
|
|
63
|
+
return true
|
|
47
64
|
}
|
|
48
65
|
|
|
49
66
|
export const DEFAULT_INTERNAL_TX_SOURCES = internalTxSourcesFromList([
|
package/src/logic/common.ts
CHANGED
|
@@ -21,9 +21,10 @@ import { getNodeApi } from '../network/node'
|
|
|
21
21
|
import { buildStakingTransactionParams, prepareStakingIntent, STAKING_CONTRACTS } from '../staking'
|
|
22
22
|
import { isNative, TransactionTypes } from '../types'
|
|
23
23
|
import { getErc20Data } from './getErc20Data'
|
|
24
|
+
import { isRecord } from './predicates'
|
|
24
25
|
|
|
25
26
|
export function isApiGasOptions(options: unknown): options is ApiGasOptions {
|
|
26
|
-
if (!options
|
|
27
|
+
if (!isRecord(options)) return false
|
|
27
28
|
|
|
28
29
|
return (
|
|
29
30
|
'slow' in options &&
|
|
@@ -36,7 +37,7 @@ export function isApiGasOptions(options: unknown): options is ApiGasOptions {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export function isApiFeeData(fees: unknown): fees is ApiFeeData {
|
|
39
|
-
if (!fees
|
|
40
|
+
if (!isRecord(fees)) return false
|
|
40
41
|
|
|
41
42
|
const isBigIntOrNull = (value: unknown): boolean => value === null || typeof value === 'bigint'
|
|
42
43
|
|
|
@@ -101,6 +102,15 @@ export function getCallData(intent: TransactionIntent<MemoNotSupported, BufferTx
|
|
|
101
102
|
: getErc20Data(intent.recipient, intent.amount)
|
|
102
103
|
}
|
|
103
104
|
|
|
105
|
+
function transactionRecipient(
|
|
106
|
+
asset: TransactionIntent<MemoNotSupported, BufferTxData>['asset'],
|
|
107
|
+
recipient: string
|
|
108
|
+
): string {
|
|
109
|
+
if (isNative(asset)) return recipient
|
|
110
|
+
if (typeof asset.assetReference === 'string') return asset.assetReference
|
|
111
|
+
throw new Error('token asset is missing assetReference')
|
|
112
|
+
}
|
|
113
|
+
|
|
104
114
|
function buildSendTxParams(intent: TransactionIntent<MemoNotSupported, BufferTxData>): {
|
|
105
115
|
to: string
|
|
106
116
|
data: Buffer
|
|
@@ -108,7 +118,7 @@ function buildSendTxParams(intent: TransactionIntent<MemoNotSupported, BufferTxD
|
|
|
108
118
|
} {
|
|
109
119
|
const { amount, asset, recipient } = intent
|
|
110
120
|
return {
|
|
111
|
-
to:
|
|
121
|
+
to: transactionRecipient(asset, recipient),
|
|
112
122
|
data: getCallData(intent),
|
|
113
123
|
value: isNative(asset) ? amount : 0n,
|
|
114
124
|
}
|
|
@@ -6,7 +6,6 @@ import type {
|
|
|
6
6
|
BufferTxData,
|
|
7
7
|
CraftedTransaction,
|
|
8
8
|
FeeEstimation,
|
|
9
|
-
FeesStrategy,
|
|
10
9
|
MemoNotSupported,
|
|
11
10
|
TransactionIntent,
|
|
12
11
|
} from '@ledgerhq/coin-module-framework/api/types'
|
|
@@ -17,6 +16,7 @@ import { getNodeApi } from '../network/node'
|
|
|
17
16
|
import { TransactionTypes } from '../types'
|
|
18
17
|
import { prepareUnsignedTxParams } from './common'
|
|
19
18
|
import { getNextSequence } from './getNextSequence'
|
|
19
|
+
import { isFeesStrategy } from './predicates'
|
|
20
20
|
|
|
21
21
|
export async function craftTransaction(
|
|
22
22
|
context: EvmContext,
|
|
@@ -83,7 +83,9 @@ export async function craftTransaction(
|
|
|
83
83
|
const node = getNodeApi(config, currencyId, context.logger)
|
|
84
84
|
const feeData = await node.getFeeData(config, currencyId, {
|
|
85
85
|
type,
|
|
86
|
-
feesStrategy: customFees?.parameters?.feesStrategy
|
|
86
|
+
feesStrategy: isFeesStrategy(customFees?.parameters?.feesStrategy)
|
|
87
|
+
? customFees.parameters.feesStrategy
|
|
88
|
+
: undefined,
|
|
87
89
|
})
|
|
88
90
|
|
|
89
91
|
if (type === TransactionTypes.legacy && feeData.gasPrice) {
|
|
@@ -7,7 +7,6 @@ import type { ApiFeeData, ApiGasOptions, FeeData, GasOptions } from '../types'
|
|
|
7
7
|
import type {
|
|
8
8
|
BufferTxData,
|
|
9
9
|
FeeEstimation,
|
|
10
|
-
FeesStrategy,
|
|
11
10
|
MemoNotSupported,
|
|
12
11
|
TransactionIntent,
|
|
13
12
|
} from '@ledgerhq/coin-module-framework/api/index'
|
|
@@ -23,6 +22,7 @@ import { STAKING_CONTRACTS } from '../staking'
|
|
|
23
22
|
import { TransactionTypes } from '../types'
|
|
24
23
|
import { getTransactionType, prepareUnsignedTxParams } from './common'
|
|
25
24
|
import { getNextSequence } from './getNextSequence'
|
|
25
|
+
import { isFeesStrategy } from './predicates'
|
|
26
26
|
|
|
27
27
|
const SEND_MAX_L1_FEE_BUFFER = new BigNumber(2)
|
|
28
28
|
|
|
@@ -159,7 +159,9 @@ export async function estimateFees(
|
|
|
159
159
|
finalFeeData: FeeData
|
|
160
160
|
finalGasOptions?: GasOptions
|
|
161
161
|
}> => {
|
|
162
|
-
const feesStrategy = customFeesParameters?.feesStrategy
|
|
162
|
+
const feesStrategy = isFeesStrategy(customFeesParameters?.feesStrategy)
|
|
163
|
+
? customFeesParameters.feesStrategy
|
|
164
|
+
: undefined
|
|
163
165
|
|
|
164
166
|
if (feesStrategy === 'custom') {
|
|
165
167
|
return { finalFeeData: extractFeeData(customFeesParameters) }
|
|
@@ -173,7 +175,6 @@ export async function estimateFees(
|
|
|
173
175
|
|
|
174
176
|
const gasTracker = getGasTracker(config)
|
|
175
177
|
const remoteGasOptions = await gasTracker?.getGasOptions({
|
|
176
|
-
currencyId,
|
|
177
178
|
config,
|
|
178
179
|
options: { useEIP1559: txType === TransactionTypes.eip1559 },
|
|
179
180
|
})
|
package/src/logic/getBalance.ts
CHANGED
|
@@ -28,7 +28,7 @@ export async function getBalance(
|
|
|
28
28
|
): Promise<Balance[]> {
|
|
29
29
|
const config = await context.config(currencyId)
|
|
30
30
|
const nodeApi = getNodeApi(config, currencyId, context.logger)
|
|
31
|
-
const explorerApi = getExplorerApi(config
|
|
31
|
+
const explorerApi = getExplorerApi(config)
|
|
32
32
|
|
|
33
33
|
const [nativeBalance, tokensBalances] = await Promise.all([
|
|
34
34
|
getNativeBalance(currencyId, address, nodeApi),
|
|
@@ -42,7 +42,7 @@ async function runInternalTxSources(
|
|
|
42
42
|
try {
|
|
43
43
|
return await fetchers[source](height)
|
|
44
44
|
} catch (error) {
|
|
45
|
-
if (
|
|
45
|
+
if (error instanceof SourceUnavailableError) {
|
|
46
46
|
hadUnavailableSource = true
|
|
47
47
|
continue
|
|
48
48
|
}
|
|
@@ -111,7 +111,7 @@ export function makeSourceFetchers(
|
|
|
111
111
|
if (!isEtherscanLikeExplorerConfig(explorer)) {
|
|
112
112
|
return Promise.reject(
|
|
113
113
|
new SourceUnavailableError(
|
|
114
|
-
`explorer internal txs not configured for currency ${
|
|
114
|
+
`explorer internal txs not configured for currency ${config.name}`
|
|
115
115
|
)
|
|
116
116
|
)
|
|
117
117
|
}
|
|
@@ -60,7 +60,7 @@ export async function listOperations(
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
const config = await context.config(currencyId)
|
|
63
|
-
const explorerApi = getExplorerApi(config
|
|
63
|
+
const explorerApi = getExplorerApi(config)
|
|
64
64
|
const explorerOrder = options.limit === undefined ? 'desc' : (options.order ?? 'desc')
|
|
65
65
|
const {
|
|
66
66
|
lastCoinOperations,
|