@ledgerhq/coin-evm 8.0.0 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/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/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 +52 -31
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/rpc.errors.d.ts +1 -3
- package/lib/network/node/rpc.errors.d.ts.map +1 -1
- package/lib/network/node/rpc.errors.js +21 -2
- package/lib/network/node/rpc.errors.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/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 +53 -32
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/rpc.errors.d.ts +1 -3
- package/lib-es/network/node/rpc.errors.d.ts.map +1 -1
- package/lib-es/network/node/rpc.errors.js +20 -2
- package/lib-es/network/node/rpc.errors.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/index.integ.test.ts +7 -6
- package/src/api/index.test.ts +2 -2
- package/src/api/index.ts +1 -2
- 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 +207 -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/rpc.common.ts +107 -30
- package/src/network/node/rpc.errors.test.ts +53 -1
- package/src/network/node/rpc.errors.ts +25 -2
- package/src/network/node/rpc.test.ts +106 -47
- 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 +96 -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 +15 -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 +30 -26
- package/src/types/staking.ts +9 -2
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
isRpcMethodNotAvailableOnChainError,
|
|
6
|
+
isRpcMethodNotImplementedError,
|
|
7
|
+
isUnsupportedRpcMethodErrorMsg,
|
|
8
|
+
} from './rpc.errors'
|
|
5
9
|
|
|
6
10
|
describe('isRpcMethodNotImplementedError', () => {
|
|
7
11
|
it.each([
|
|
@@ -28,3 +32,51 @@ describe('isRpcMethodNotImplementedError', () => {
|
|
|
28
32
|
expect(isRpcMethodNotImplementedError(error)).toBe(false)
|
|
29
33
|
})
|
|
30
34
|
})
|
|
35
|
+
|
|
36
|
+
describe('isUnsupportedRpcMethodErrorMsg', () => {
|
|
37
|
+
it.each([
|
|
38
|
+
[{ code: -32000, message: 'required historical state unavailable (reexec=0)' }],
|
|
39
|
+
[{ code: 27, message: 'Unknown state. First available state is 14823652' }],
|
|
40
|
+
])('is true for %j', (error) => {
|
|
41
|
+
expect(isUnsupportedRpcMethodErrorMsg(error)).toBe(true)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it.each([
|
|
45
|
+
[{ code: -32000, message: 'execution reverted' }],
|
|
46
|
+
[{ code: 'TIMEOUT', message: 'timeout' }],
|
|
47
|
+
])('is false for %j', (error) => {
|
|
48
|
+
expect(isUnsupportedRpcMethodErrorMsg(error)).toBe(false)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe('isRpcMethodNotAvailableOnChainError', () => {
|
|
53
|
+
const alchemyMessage =
|
|
54
|
+
'trace_block is not available on the ASTAR_MAINNET. For more information see our docs: https://docs.alchemy.com/alchemy/documentation/apis/ethereum'
|
|
55
|
+
|
|
56
|
+
it.each([
|
|
57
|
+
[{ code: -32600, message: alchemyMessage }],
|
|
58
|
+
[
|
|
59
|
+
{
|
|
60
|
+
code: 'SERVER_ERROR',
|
|
61
|
+
info: {
|
|
62
|
+
responseStatus: '400 Bad Request',
|
|
63
|
+
responseBody: JSON.stringify({
|
|
64
|
+
jsonrpc: '2.0',
|
|
65
|
+
id: 1,
|
|
66
|
+
error: { code: -32600, message: alchemyMessage },
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
])('is true for %j', (error) => {
|
|
72
|
+
expect(isRpcMethodNotAvailableOnChainError(error)).toBe(true)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it.each([
|
|
76
|
+
[{ code: -32600, message: 'invalid request' }],
|
|
77
|
+
[{ code: -32000, message: 'header not found' }],
|
|
78
|
+
[{ code: 'TIMEOUT', message: 'timeout' }],
|
|
79
|
+
])('is false for %j', (error) => {
|
|
80
|
+
expect(isRpcMethodNotAvailableOnChainError(error)).toBe(false)
|
|
81
|
+
})
|
|
82
|
+
})
|
|
@@ -43,10 +43,33 @@ export function isRpcMethodNotImplementedError(error: unknown): boolean {
|
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* call this function when RPC returns a generic code, like -32000 which can be used for different errors
|
|
46
|
+
*
|
|
47
|
+
* - "required historical state unavailable": geth node without the state for the requested block
|
|
48
|
+
* - "unknown state": Alchemy node without the state for the requested block
|
|
49
|
+
* (e.g. "Unknown state. First available state is 14823652")
|
|
46
50
|
*/
|
|
51
|
+
const HISTORICAL_STATE_UNAVAILABLE_MARKERS = [
|
|
52
|
+
'required historical state unavailable',
|
|
53
|
+
'unknown state',
|
|
54
|
+
]
|
|
55
|
+
|
|
47
56
|
export function isUnsupportedRpcMethodErrorMsg(error: unknown): boolean {
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
return collectRpcErrorFields(error).messages.some((m) => {
|
|
58
|
+
const message = m.toLowerCase()
|
|
59
|
+
return HISTORICAL_STATE_UNAVAILABLE_MARKERS.some((marker) => message.includes(marker))
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Alchemy rejects methods it does not serve on a chain with a generic -32600 code and a message like
|
|
65
|
+
* "trace_block is not available on the ASTAR_MAINNET".
|
|
66
|
+
*/
|
|
67
|
+
const RPC_METHOD_NOT_AVAILABLE_ON_CHAIN_MESSAGE = /\b\w+_\w+ is not available on\b/i
|
|
68
|
+
|
|
69
|
+
export function isRpcMethodNotAvailableOnChainError(error: unknown): boolean {
|
|
70
|
+
return collectRpcErrorFields(error).messages.some((m) =>
|
|
71
|
+
RPC_METHOD_NOT_AVAILABLE_ON_CHAIN_MESSAGE.test(m)
|
|
72
|
+
)
|
|
50
73
|
}
|
|
51
74
|
|
|
52
75
|
function extractRpcErrorCode(key: string, field: unknown): string | null {
|
|
@@ -7,7 +7,11 @@ import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
|
7
7
|
import BigNumber from 'bignumber.js'
|
|
8
8
|
import { FeeData, FetchRequest, JsonRpcProvider, Network, Transaction } from 'ethers'
|
|
9
9
|
import { GasEstimationError, InsufficientFunds, UnsupportedRpcMethodError } from '../../errors'
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
createMockEvmConfigInfo,
|
|
12
|
+
mkExternalNode,
|
|
13
|
+
testLogger,
|
|
14
|
+
} from '../../fixtures/context.fixtures'
|
|
11
15
|
import {
|
|
12
16
|
mkBlock,
|
|
13
17
|
mkTransactionReceipt,
|
|
@@ -32,11 +36,15 @@ const evmConfig = createMockEvmConfigInfo({
|
|
|
32
36
|
node: mkExternalNode({ uri: 'http://test' }),
|
|
33
37
|
})
|
|
34
38
|
|
|
35
|
-
const nodeApi = createNodeApi(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const nodeApi = createNodeApi(
|
|
40
|
+
evmConfig,
|
|
41
|
+
{
|
|
42
|
+
type: 'external',
|
|
43
|
+
uri: 'http://test',
|
|
44
|
+
retries: DEFAULT_RETRIES_RPC_METHODS,
|
|
45
|
+
},
|
|
46
|
+
testLogger
|
|
47
|
+
)
|
|
40
48
|
|
|
41
49
|
jest.useFakeTimers()
|
|
42
50
|
|
|
@@ -359,7 +367,7 @@ describe('EVM Family', () => {
|
|
|
359
367
|
},
|
|
360
368
|
]
|
|
361
369
|
|
|
362
|
-
const result = parseERC20TransfersFromLogs(logs)
|
|
370
|
+
const result = parseERC20TransfersFromLogs(logs, testLogger)
|
|
363
371
|
|
|
364
372
|
expect(result).toEqual([
|
|
365
373
|
{
|
|
@@ -397,7 +405,7 @@ describe('EVM Family', () => {
|
|
|
397
405
|
},
|
|
398
406
|
]
|
|
399
407
|
|
|
400
|
-
const result = parseERC20TransfersFromLogs(logs)
|
|
408
|
+
const result = parseERC20TransfersFromLogs(logs, testLogger)
|
|
401
409
|
expect(result.map((r) => r.value)).toEqual([
|
|
402
410
|
'5480989920044678351000',
|
|
403
411
|
'81274972180027185554775',
|
|
@@ -426,7 +434,7 @@ describe('EVM Family', () => {
|
|
|
426
434
|
},
|
|
427
435
|
]
|
|
428
436
|
|
|
429
|
-
const result = parseERC20TransfersFromLogs(logs)
|
|
437
|
+
const result = parseERC20TransfersFromLogs(logs, testLogger)
|
|
430
438
|
// Only the Transfer, not the Approval
|
|
431
439
|
expect(result.map((r) => r.value)).toEqual(['1'])
|
|
432
440
|
})
|
|
@@ -440,13 +448,13 @@ describe('EVM Family', () => {
|
|
|
440
448
|
},
|
|
441
449
|
]
|
|
442
450
|
|
|
443
|
-
const result = parseERC20TransfersFromLogs(logs)
|
|
451
|
+
const result = parseERC20TransfersFromLogs(logs, testLogger)
|
|
444
452
|
|
|
445
453
|
expect(result).toHaveLength(0)
|
|
446
454
|
})
|
|
447
455
|
|
|
448
456
|
it('should handle empty logs array', () => {
|
|
449
|
-
expect(parseERC20TransfersFromLogs([])).toEqual([])
|
|
457
|
+
expect(parseERC20TransfersFromLogs([], testLogger)).toEqual([])
|
|
450
458
|
})
|
|
451
459
|
|
|
452
460
|
describe('EIP-7708 SYSTEM_ADDRESS logs', () => {
|
|
@@ -462,14 +470,17 @@ describe('EVM Family', () => {
|
|
|
462
470
|
})
|
|
463
471
|
|
|
464
472
|
it('should skip Transfer-shaped logs emitted by SYSTEM_ADDRESS', () => {
|
|
465
|
-
expect(
|
|
473
|
+
expect(
|
|
474
|
+
parseERC20TransfersFromLogs([makeSystemTransferLog(SYSTEM_ADDRESS)], testLogger)
|
|
475
|
+
).toEqual([])
|
|
466
476
|
})
|
|
467
477
|
|
|
468
478
|
it('should skip SYSTEM_ADDRESS logs whatever the case of the emitter', () => {
|
|
469
479
|
expect(
|
|
470
|
-
parseERC20TransfersFromLogs(
|
|
471
|
-
makeSystemTransferLog('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfE'),
|
|
472
|
-
|
|
480
|
+
parseERC20TransfersFromLogs(
|
|
481
|
+
[makeSystemTransferLog('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfE')],
|
|
482
|
+
testLogger
|
|
483
|
+
)
|
|
473
484
|
).toEqual([])
|
|
474
485
|
})
|
|
475
486
|
|
|
@@ -493,7 +504,7 @@ describe('EVM Family', () => {
|
|
|
493
504
|
},
|
|
494
505
|
]
|
|
495
506
|
|
|
496
|
-
expect(parseERC20TransfersFromLogs(logs)).toEqual([])
|
|
507
|
+
expect(parseERC20TransfersFromLogs(logs, testLogger)).toEqual([])
|
|
497
508
|
})
|
|
498
509
|
|
|
499
510
|
it('should still parse a genuine ERC20 Transfer sitting next to a system log', () => {
|
|
@@ -510,7 +521,7 @@ describe('EVM Family', () => {
|
|
|
510
521
|
},
|
|
511
522
|
]
|
|
512
523
|
|
|
513
|
-
const result = parseERC20TransfersFromLogs(logs)
|
|
524
|
+
const result = parseERC20TransfersFromLogs(logs, testLogger)
|
|
514
525
|
|
|
515
526
|
expect(result).toEqual([
|
|
516
527
|
{
|
|
@@ -564,7 +575,7 @@ describe('EVM Family', () => {
|
|
|
564
575
|
// Note: ERC-1155 uses different event signatures (TransferSingle/TransferBatch)
|
|
565
576
|
// so it's already filtered out by the topic[0] check, not by topics.length
|
|
566
577
|
|
|
567
|
-
const result = parseERC20TransfersFromLogs(logs)
|
|
578
|
+
const result = parseERC20TransfersFromLogs(logs, testLogger)
|
|
568
579
|
|
|
569
580
|
expect(result.map((r) => r.value)).toEqual(['1'])
|
|
570
581
|
})
|
|
@@ -583,7 +594,7 @@ describe('EVM Family', () => {
|
|
|
583
594
|
},
|
|
584
595
|
]
|
|
585
596
|
|
|
586
|
-
const result = parseERC20TransfersFromLogs(logs)
|
|
597
|
+
const result = parseERC20TransfersFromLogs(logs, testLogger)
|
|
587
598
|
|
|
588
599
|
expect(result).toEqual([])
|
|
589
600
|
})
|
|
@@ -600,7 +611,7 @@ describe('EVM Family', () => {
|
|
|
600
611
|
},
|
|
601
612
|
]
|
|
602
613
|
|
|
603
|
-
const result = parseERC20TransfersFromLogs(logs)
|
|
614
|
+
const result = parseERC20TransfersFromLogs(logs, testLogger)
|
|
604
615
|
|
|
605
616
|
expect(result).toEqual([
|
|
606
617
|
{
|
|
@@ -627,7 +638,7 @@ describe('EVM Family', () => {
|
|
|
627
638
|
},
|
|
628
639
|
]
|
|
629
640
|
|
|
630
|
-
const result = parseERC20TransfersFromLogs(logs)
|
|
641
|
+
const result = parseERC20TransfersFromLogs(logs, testLogger)
|
|
631
642
|
|
|
632
643
|
expect(result).toEqual([
|
|
633
644
|
{
|
|
@@ -645,16 +656,19 @@ describe('EVM Family', () => {
|
|
|
645
656
|
it('parses Mint as Transfer from 0x0', () => {
|
|
646
657
|
const MINT_TOPIC = '0x0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885'
|
|
647
658
|
const L2_BASE_TOKEN = '0x000000000000000000000000000000000000800A'
|
|
648
|
-
const result = parseERC20TransfersFromLogs(
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
659
|
+
const result = parseERC20TransfersFromLogs(
|
|
660
|
+
[
|
|
661
|
+
{
|
|
662
|
+
address: L2_BASE_TOKEN,
|
|
663
|
+
topics: [
|
|
664
|
+
MINT_TOPIC,
|
|
665
|
+
'0x000000000000000000000000beb30f27e61efff46aa27dce18e23ee8d5a7c6a4',
|
|
666
|
+
],
|
|
667
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000064',
|
|
668
|
+
},
|
|
669
|
+
],
|
|
670
|
+
testLogger
|
|
671
|
+
)
|
|
658
672
|
expect(result).toEqual([
|
|
659
673
|
{
|
|
660
674
|
asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
|
|
@@ -1204,6 +1218,38 @@ describe('EVM Family', () => {
|
|
|
1204
1218
|
})
|
|
1205
1219
|
})
|
|
1206
1220
|
|
|
1221
|
+
it('should throw when the node returns an empty stub block (zero timestamp)', async () => {
|
|
1222
|
+
// not mockResolvedValueOnce: the node API retries on error
|
|
1223
|
+
jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValue(
|
|
1224
|
+
mkBlock({
|
|
1225
|
+
hash: '0x9196eeae33b2e2a2080a9660a1b2554cf01260129756e26fc17e5cbd883bdb61',
|
|
1226
|
+
number: 956855,
|
|
1227
|
+
timestamp: 0,
|
|
1228
|
+
transactions: [],
|
|
1229
|
+
})
|
|
1230
|
+
)
|
|
1231
|
+
|
|
1232
|
+
await expect(nodeApi.getBlockByHeight(currencyId, 956855)).rejects.toThrow(
|
|
1233
|
+
'Block 956855 not found (the node returned an empty stub block)'
|
|
1234
|
+
)
|
|
1235
|
+
})
|
|
1236
|
+
|
|
1237
|
+
it('should accept a zero timestamp on the genesis block', async () => {
|
|
1238
|
+
jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce(
|
|
1239
|
+
mkBlock({
|
|
1240
|
+
hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
|
|
1241
|
+
number: 0,
|
|
1242
|
+
timestamp: 0,
|
|
1243
|
+
transactions: [],
|
|
1244
|
+
})
|
|
1245
|
+
)
|
|
1246
|
+
|
|
1247
|
+
await expect(nodeApi.getBlockByHeight(currencyId, 0)).resolves.toMatchObject({
|
|
1248
|
+
height: 0,
|
|
1249
|
+
timestamp: 0,
|
|
1250
|
+
})
|
|
1251
|
+
})
|
|
1252
|
+
|
|
1207
1253
|
it('should prefetch block transactions when requested', async () => {
|
|
1208
1254
|
jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce(
|
|
1209
1255
|
mkBlock({
|
|
@@ -1485,6 +1531,12 @@ describe('EVM Family', () => {
|
|
|
1485
1531
|
message: 'API key is not allowed to access method',
|
|
1486
1532
|
label: '-32053 (e.g. API key cannot call trace_block)',
|
|
1487
1533
|
},
|
|
1534
|
+
{
|
|
1535
|
+
code: -32600,
|
|
1536
|
+
message:
|
|
1537
|
+
'trace_block is not available on the ASTAR_MAINNET. For more information see our docs: https://docs.alchemy.com/alchemy/documentation/apis/ethereum',
|
|
1538
|
+
label: '-32600 (e.g. Alchemy method not available on chain)',
|
|
1539
|
+
},
|
|
1488
1540
|
])(
|
|
1489
1541
|
'should throw UnsupportedRpcMethodError when trace_block returns $label',
|
|
1490
1542
|
async ({ code, message }) => {
|
|
@@ -1574,24 +1626,31 @@ describe('EVM Family', () => {
|
|
|
1574
1626
|
}
|
|
1575
1627
|
)
|
|
1576
1628
|
|
|
1577
|
-
it(
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1629
|
+
it.each([
|
|
1630
|
+
{ code: -32000, message: 'required historical state unavailable (reexec=0)', label: 'geth' },
|
|
1631
|
+
{
|
|
1632
|
+
code: 27,
|
|
1633
|
+
message: 'Unknown state. First available state is 14823652',
|
|
1634
|
+
label: 'Alchemy',
|
|
1635
|
+
},
|
|
1636
|
+
])(
|
|
1637
|
+
'throws UnsupportedRpcMethodError when debug_traceBlockByNumber reports historical state unavailable ($label)',
|
|
1638
|
+
async ({ code, message }) => {
|
|
1639
|
+
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementation(async (method: string) => {
|
|
1640
|
+
if (method === 'debug_traceBlockByNumber') {
|
|
1641
|
+
throw { code, message }
|
|
1583
1642
|
}
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
})
|
|
1643
|
+
throw new Error(`Method not mocked: ${method}`)
|
|
1644
|
+
})
|
|
1587
1645
|
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1646
|
+
const err = await nodeApi.traceBlockGeth!(currencyId, 1).then(
|
|
1647
|
+
() => null,
|
|
1648
|
+
(e: unknown) => e
|
|
1649
|
+
)
|
|
1650
|
+
expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
|
|
1651
|
+
expect(err).toMatchObject({ method: 'debug_traceBlockByNumber' })
|
|
1652
|
+
}
|
|
1653
|
+
)
|
|
1595
1654
|
})
|
|
1596
1655
|
|
|
1597
1656
|
describe('getOptimismAdditionalFees', () => {
|
package/src/staking/contracts.ts
CHANGED
|
@@ -189,9 +189,9 @@ export const STAKING_CONTRACTS: Record<string, StakingContractConfig> = {
|
|
|
189
189
|
// Including the delegation-queue delay (1–2 epochs), the maximum wait is ~3 epochs ≈ 17 h.
|
|
190
190
|
// Source: https://docs.monad.xyz/monad-arch/consensus/staking (WITHDRAWAL_DELAY constant)
|
|
191
191
|
unbondingPeriodDays: 0.75,
|
|
192
|
-
resolveValidatorAddress: (config, d, _contractAddress) => {
|
|
192
|
+
resolveValidatorAddress: (config, d, _contractAddress, logger) => {
|
|
193
193
|
return typeof d[0] === 'bigint'
|
|
194
|
-
? getValidatorAddressById(config, 'monad', d[0])
|
|
194
|
+
? getValidatorAddressById(config, 'monad', d[0], logger)
|
|
195
195
|
: Promise.resolve(null)
|
|
196
196
|
},
|
|
197
197
|
resolveOperationAmount: async (_config, decoded, operationType) => {
|
package/src/staking/fetchers.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
StakingStrategy,
|
|
10
10
|
} from '../types/staking'
|
|
11
11
|
import type { Stake, Validator } from '@ledgerhq/coin-module-framework/api/types'
|
|
12
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
12
13
|
import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
13
14
|
import { evmUnit } from '../logic/evmUnit'
|
|
14
15
|
import { withApi } from '../network/node/rpc.common'
|
|
@@ -29,18 +30,28 @@ const createStakingFetcher = (
|
|
|
29
30
|
getValidatorsFn: (
|
|
30
31
|
evmConfig: EvmConfigInfo,
|
|
31
32
|
config: StakingContractConfig,
|
|
32
|
-
currencyId: string
|
|
33
|
+
currencyId: string,
|
|
34
|
+
logger: Logger
|
|
33
35
|
) => Promise<Validator[]>
|
|
34
36
|
) => {
|
|
35
37
|
return async (
|
|
36
38
|
evmConfig: EvmConfigInfo,
|
|
37
39
|
address: string,
|
|
38
40
|
config: StakingContractConfig,
|
|
39
|
-
currencyId: string
|
|
41
|
+
currencyId: string,
|
|
42
|
+
logger: Logger,
|
|
43
|
+
_knownValIds?: string[]
|
|
40
44
|
): Promise<Stake[]> => {
|
|
41
|
-
const validators = await getValidatorsFn(evmConfig, config, currencyId)
|
|
45
|
+
const validators = await getValidatorsFn(evmConfig, config, currencyId, logger)
|
|
42
46
|
const validatorAddresses = validators.map((v) => v.address)
|
|
43
|
-
return getStakesForValidators(
|
|
47
|
+
return getStakesForValidators(
|
|
48
|
+
evmConfig,
|
|
49
|
+
address,
|
|
50
|
+
config,
|
|
51
|
+
currencyId,
|
|
52
|
+
validatorAddresses,
|
|
53
|
+
logger
|
|
54
|
+
)
|
|
44
55
|
}
|
|
45
56
|
}
|
|
46
57
|
|
|
@@ -48,8 +59,8 @@ export const STAKING_CONFIG: Record<string, StakingStrategy> = {
|
|
|
48
59
|
sei_evm: {
|
|
49
60
|
// Sei returns its whole validator set in a single page, so the first page's
|
|
50
61
|
// items are the complete list.
|
|
51
|
-
fetcher: createStakingFetcher(async (evmConfig, _config, currencyId) => {
|
|
52
|
-
const { items } = await getValidators(evmConfig, currencyId)
|
|
62
|
+
fetcher: createStakingFetcher(async (evmConfig, _config, currencyId, logger) => {
|
|
63
|
+
const { items } = await getValidators(evmConfig, currencyId, logger)
|
|
53
64
|
return items
|
|
54
65
|
}),
|
|
55
66
|
},
|
|
@@ -214,7 +225,8 @@ const getStakesForValidators = async (
|
|
|
214
225
|
address: string,
|
|
215
226
|
config: StakingContractConfig,
|
|
216
227
|
currencyId: string,
|
|
217
|
-
validators: string[]
|
|
228
|
+
validators: string[],
|
|
229
|
+
logger: Logger
|
|
218
230
|
): Promise<Stake[]> => {
|
|
219
231
|
if (validators.length === 0) {
|
|
220
232
|
console.error('No validators available', { currencyId })
|
|
@@ -224,7 +236,7 @@ const getStakesForValidators = async (
|
|
|
224
236
|
// Fired here so its latency overlaps the precompile batch loop below;
|
|
225
237
|
// awaited at the end. Any failure resolves to an empty map so the staking
|
|
226
238
|
// sync never blocks on the off-chain rewards call.
|
|
227
|
-
const rewardsPromise = fetchRewards(evmConfig, currencyId, address).catch(
|
|
239
|
+
const rewardsPromise = fetchRewards(evmConfig, currencyId, address, logger).catch(
|
|
228
240
|
() => new Map<string, bigint>()
|
|
229
241
|
)
|
|
230
242
|
|
|
@@ -7,7 +7,7 @@ import type { TransactionRequest } from 'ethers'
|
|
|
7
7
|
import { createStakingTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
|
|
8
8
|
import { ethers } from 'ethers'
|
|
9
9
|
import zeroGravityAbi from '../abis/zero_gravity-validator.abi.json'
|
|
10
|
-
import { createMockEvmConfigInfo, mkExternalNode } from '../fixtures/context.fixtures'
|
|
10
|
+
import { createMockEvmConfigInfo, mkExternalNode, testLogger } from '../fixtures/context.fixtures'
|
|
11
11
|
import { withApi } from '../network/node/rpc.common'
|
|
12
12
|
import { isExternalNodeConfig } from '../network/node/types'
|
|
13
13
|
import { prepareStakingIntent } from './prepareIntents'
|
|
@@ -88,7 +88,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
|
|
|
88
88
|
const result = await prepareStakingIntent(
|
|
89
89
|
mockConfig,
|
|
90
90
|
'zero_gravity',
|
|
91
|
-
makeIntent({ useAllAmount: false })
|
|
91
|
+
makeIntent({ useAllAmount: false }),
|
|
92
|
+
testLogger
|
|
92
93
|
)
|
|
93
94
|
|
|
94
95
|
expect(result).toMatchObject({ shares: 1_500_000_000n, txValue: 5n * 10n ** 9n })
|
|
@@ -98,7 +99,12 @@ describe('prepareStakingIntent / zero_gravity', () => {
|
|
|
98
99
|
setupProvider(makeCallHandler({ getDelegationShares: 0n }))
|
|
99
100
|
|
|
100
101
|
await expect(
|
|
101
|
-
prepareStakingIntent(
|
|
102
|
+
prepareStakingIntent(
|
|
103
|
+
mockConfig,
|
|
104
|
+
'zero_gravity',
|
|
105
|
+
makeIntent({ useAllAmount: false }),
|
|
106
|
+
testLogger
|
|
107
|
+
)
|
|
102
108
|
).rejects.toThrow('no shares to undelegate from this validator')
|
|
103
109
|
})
|
|
104
110
|
|
|
@@ -114,7 +120,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
|
|
|
114
120
|
const result = await prepareStakingIntent(
|
|
115
121
|
mockConfig,
|
|
116
122
|
'zero_gravity',
|
|
117
|
-
makeIntent({ useAllAmount: false })
|
|
123
|
+
makeIntent({ useAllAmount: false }),
|
|
124
|
+
testLogger
|
|
118
125
|
)
|
|
119
126
|
|
|
120
127
|
expect(result).toMatchObject({ shares: 2_000_000_000n })
|
|
@@ -132,7 +139,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
|
|
|
132
139
|
const result = await prepareStakingIntent(
|
|
133
140
|
mockConfig,
|
|
134
141
|
'zero_gravity',
|
|
135
|
-
makeIntent({ useAllAmount: false })
|
|
142
|
+
makeIntent({ useAllAmount: false }),
|
|
143
|
+
testLogger
|
|
136
144
|
)
|
|
137
145
|
|
|
138
146
|
expect(result).toMatchObject({ shares: 1_000_000_000n })
|
|
@@ -148,7 +156,12 @@ describe('prepareStakingIntent / zero_gravity', () => {
|
|
|
148
156
|
)
|
|
149
157
|
|
|
150
158
|
await expect(
|
|
151
|
-
prepareStakingIntent(
|
|
159
|
+
prepareStakingIntent(
|
|
160
|
+
mockConfig,
|
|
161
|
+
'zero_gravity',
|
|
162
|
+
makeIntent({ useAllAmount: false }),
|
|
163
|
+
testLogger
|
|
164
|
+
)
|
|
152
165
|
).rejects.toThrow('requested amount exceeds delegated shares')
|
|
153
166
|
})
|
|
154
167
|
|
|
@@ -162,7 +175,12 @@ describe('prepareStakingIntent / zero_gravity', () => {
|
|
|
162
175
|
)
|
|
163
176
|
|
|
164
177
|
await expect(
|
|
165
|
-
prepareStakingIntent(
|
|
178
|
+
prepareStakingIntent(
|
|
179
|
+
mockConfig,
|
|
180
|
+
'zero_gravity',
|
|
181
|
+
makeIntent({ useAllAmount: false }),
|
|
182
|
+
testLogger
|
|
183
|
+
)
|
|
166
184
|
).rejects.toThrow('shares below 0G contract minimum')
|
|
167
185
|
})
|
|
168
186
|
|
|
@@ -172,7 +190,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
|
|
|
172
190
|
const result = await prepareStakingIntent(
|
|
173
191
|
mockConfig,
|
|
174
192
|
'zero_gravity',
|
|
175
|
-
makeIntent({ useAllAmount: true })
|
|
193
|
+
makeIntent({ useAllAmount: true }),
|
|
194
|
+
testLogger
|
|
176
195
|
)
|
|
177
196
|
|
|
178
197
|
expect(result).toMatchObject({ shares: 1_000_000_000n, txValue: 5n * 10n ** 9n })
|
|
@@ -182,7 +201,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
|
|
|
182
201
|
const result = await prepareStakingIntent(
|
|
183
202
|
mockConfig,
|
|
184
203
|
'zero_gravity',
|
|
185
|
-
makeIntent({ shares: 42n })
|
|
204
|
+
makeIntent({ shares: 42n }),
|
|
205
|
+
testLogger
|
|
186
206
|
)
|
|
187
207
|
|
|
188
208
|
expect(result).toMatchObject({
|
|
@@ -197,7 +217,8 @@ describe('prepareStakingIntent / zero_gravity', () => {
|
|
|
197
217
|
const result = await prepareStakingIntent(
|
|
198
218
|
mockConfig,
|
|
199
219
|
'zero_gravity',
|
|
200
|
-
makeIntent({ mode: 'delegate' })
|
|
220
|
+
makeIntent({ mode: 'delegate' }),
|
|
221
|
+
testLogger
|
|
201
222
|
)
|
|
202
223
|
|
|
203
224
|
expect(result).toMatchObject({
|
|
@@ -210,7 +231,7 @@ describe('prepareStakingIntent / zero_gravity', () => {
|
|
|
210
231
|
it('is a no-op when node is not external', async () => {
|
|
211
232
|
mockedIsExternalNodeConfig.mockReturnValue(false)
|
|
212
233
|
|
|
213
|
-
const result = await prepareStakingIntent(mockConfig, 'zero_gravity', makeIntent())
|
|
234
|
+
const result = await prepareStakingIntent(mockConfig, 'zero_gravity', makeIntent(), testLogger)
|
|
214
235
|
|
|
215
236
|
expect(result).toMatchObject({
|
|
216
237
|
mode: 'undelegate',
|
|
@@ -220,7 +241,7 @@ describe('prepareStakingIntent / zero_gravity', () => {
|
|
|
220
241
|
})
|
|
221
242
|
|
|
222
243
|
it('is a no-op for unknown currencies', async () => {
|
|
223
|
-
const result = await prepareStakingIntent(mockConfig, 'unknown_chain', makeIntent())
|
|
244
|
+
const result = await prepareStakingIntent(mockConfig, 'unknown_chain', makeIntent(), testLogger)
|
|
224
245
|
|
|
225
246
|
expect(result).toMatchObject({
|
|
226
247
|
mode: 'undelegate',
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
MemoNotSupported,
|
|
8
8
|
TransactionIntent,
|
|
9
9
|
} from '@ledgerhq/coin-module-framework/api/index'
|
|
10
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
10
11
|
import { ethers } from 'ethers'
|
|
11
12
|
import { isStakingIntent } from '../logic-public'
|
|
12
13
|
import { withApi } from '../network/node/rpc.common'
|
|
@@ -40,10 +41,11 @@ function isWithdrawalFeeInGweiResult(value: unknown): value is WithdrawalFeeInGw
|
|
|
40
41
|
type IntentPreparer = (
|
|
41
42
|
config: EvmConfigInfo,
|
|
42
43
|
currencyId: string,
|
|
43
|
-
intent: StakingIntent
|
|
44
|
+
intent: StakingIntent,
|
|
45
|
+
logger: Logger
|
|
44
46
|
) => Promise<StakingIntent>
|
|
45
47
|
|
|
46
|
-
const prepareMonadIntent: IntentPreparer = async (config, _currencyId, intent) => {
|
|
48
|
+
const prepareMonadIntent: IntentPreparer = async (config, _currencyId, intent, logger) => {
|
|
47
49
|
if (!isStakingIntent(intent)) return intent
|
|
48
50
|
if (intent.mode !== 'undelegate' || intent.withdrawId !== undefined || !intent.valId) {
|
|
49
51
|
return intent
|
|
@@ -53,7 +55,8 @@ const prepareMonadIntent: IntentPreparer = async (config, _currencyId, intent) =
|
|
|
53
55
|
config,
|
|
54
56
|
'monad',
|
|
55
57
|
BigInt(intent.valId),
|
|
56
|
-
intent.sender
|
|
58
|
+
intent.sender,
|
|
59
|
+
logger
|
|
57
60
|
)
|
|
58
61
|
if (withdrawId === null) {
|
|
59
62
|
throw new Error(
|
|
@@ -153,8 +156,9 @@ const STAKING_INTENT_PREPARERS: Record<string, IntentPreparer> = {
|
|
|
153
156
|
export const prepareStakingIntent = async (
|
|
154
157
|
config: EvmConfigInfo,
|
|
155
158
|
currencyId: string,
|
|
156
|
-
intent: StakingIntent
|
|
159
|
+
intent: StakingIntent,
|
|
160
|
+
logger: Logger
|
|
157
161
|
): Promise<StakingIntent> => {
|
|
158
162
|
const prepare = STAKING_INTENT_PREPARERS[currencyId]
|
|
159
|
-
return prepare ? prepare(config, currencyId, intent) : intent
|
|
163
|
+
return prepare ? prepare(config, currencyId, intent, logger) : intent
|
|
160
164
|
}
|