@ledgerhq/coin-evm 7.0.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.oxlintrc.json +1 -1
- package/CHANGELOG.md +62 -0
- package/docs/getBlock-internal-txs-schema.md +1 -1
- package/docs/network/node/index.md +3 -1
- package/lib/adapters/blockOperations.d.ts +4 -3
- package/lib/adapters/blockOperations.d.ts.map +1 -1
- package/lib/adapters/blockOperations.js +17 -17
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/adapters/etherscan.d.ts +7 -6
- package/lib/adapters/etherscan.d.ts.map +1 -1
- package/lib/adapters/etherscan.js +19 -19
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/adapters/ledger.d.ts +6 -5
- package/lib/adapters/ledger.d.ts.map +1 -1
- package/lib/adapters/ledger.js +15 -15
- package/lib/adapters/ledger.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +1 -2
- package/lib/api/index.js.map +1 -1
- package/lib/config.d.ts +0 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/logic/common.js +1 -1
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js +3 -3
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +22 -23
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getStakes.d.ts.map +1 -1
- package/lib/logic/getStakes.js +2 -2
- package/lib/logic/getStakes.js.map +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts +3 -2
- package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js +13 -10
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/listOperations.js +1 -1
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic-public/utils.d.ts +3 -2
- package/lib/logic-public/utils.d.ts.map +1 -1
- package/lib/logic-public/utils.js +7 -6
- package/lib/logic-public/utils.js.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +3 -2
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js +13 -12
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js +11 -11
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/types.d.ts +2 -2
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/explorer/types.js.map +1 -1
- package/lib/network/node/explorerProxy.js +3 -3
- package/lib/network/node/explorerProxy.js.map +1 -1
- package/lib/network/node/index.d.ts.map +1 -1
- package/lib/network/node/index.js +2 -2
- package/lib/network/node/index.js.map +1 -1
- package/lib/network/node/ledger.d.ts +2 -1
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js +9 -10
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +3 -2
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +37 -29
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/staking/contracts.js +2 -2
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/fetchers.d.ts.map +1 -1
- package/lib/staking/fetchers.js +7 -7
- package/lib/staking/fetchers.js.map +1 -1
- package/lib/staking/prepareIntents.d.ts +2 -1
- package/lib/staking/prepareIntents.d.ts.map +1 -1
- package/lib/staking/prepareIntents.js +4 -4
- package/lib/staking/prepareIntents.js.map +1 -1
- package/lib/staking/redelegations.d.ts +5 -4
- package/lib/staking/redelegations.d.ts.map +1 -1
- package/lib/staking/redelegations.js +13 -14
- package/lib/staking/redelegations.js.map +1 -1
- package/lib/staking/rewards.d.ts +2 -1
- package/lib/staking/rewards.d.ts.map +1 -1
- package/lib/staking/rewards.js +4 -5
- package/lib/staking/rewards.js.map +1 -1
- package/lib/staking/rewardsFromReceipt.d.ts +2 -1
- package/lib/staking/rewardsFromReceipt.d.ts.map +1 -1
- package/lib/staking/rewardsFromReceipt.js +2 -3
- package/lib/staking/rewardsFromReceipt.js.map +1 -1
- package/lib/staking/unbondings.d.ts +2 -1
- package/lib/staking/unbondings.d.ts.map +1 -1
- package/lib/staking/unbondings.js +4 -5
- package/lib/staking/unbondings.js.map +1 -1
- package/lib/staking/validators/index.d.ts +9 -4
- package/lib/staking/validators/index.d.ts.map +1 -1
- package/lib/staking/validators/index.js +19 -10
- package/lib/staking/validators/index.js.map +1 -1
- package/lib/staking/validators/monad.d.ts +6 -5
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js +33 -29
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/monadResolver.d.ts +2 -1
- package/lib/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib/staking/validators/monadResolver.js +2 -3
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib/staking/validators/somnia.d.ts +3 -2
- package/lib/staking/validators/somnia.d.ts.map +1 -1
- package/lib/staking/validators/somnia.js +16 -15
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/types.d.ts +2 -1
- package/lib/staking/validators/types.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.d.ts +2 -1
- package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.js +7 -8
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib/types/staking.d.ts +4 -3
- package/lib/types/staking.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.d.ts +4 -3
- package/lib-es/adapters/blockOperations.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.js +17 -17
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/adapters/etherscan.d.ts +7 -6
- package/lib-es/adapters/etherscan.d.ts.map +1 -1
- package/lib-es/adapters/etherscan.js +19 -19
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/adapters/ledger.d.ts +6 -5
- package/lib-es/adapters/ledger.d.ts.map +1 -1
- package/lib-es/adapters/ledger.js +15 -15
- package/lib-es/adapters/ledger.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +1 -2
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/config.d.ts +0 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/logic/common.js +1 -1
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js +3 -3
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +22 -23
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getStakes.d.ts.map +1 -1
- package/lib-es/logic/getStakes.js +2 -2
- package/lib-es/logic/getStakes.js.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts +3 -2
- package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js +13 -10
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/listOperations.js +1 -1
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic-public/utils.d.ts +3 -2
- package/lib-es/logic-public/utils.d.ts.map +1 -1
- package/lib-es/logic-public/utils.js +7 -6
- package/lib-es/logic-public/utils.js.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +3 -2
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js +13 -12
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js +11 -11
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +2 -2
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/explorer/types.js.map +1 -1
- package/lib-es/network/node/explorerProxy.js +3 -3
- package/lib-es/network/node/explorerProxy.js.map +1 -1
- package/lib-es/network/node/index.d.ts.map +1 -1
- package/lib-es/network/node/index.js +2 -2
- package/lib-es/network/node/index.js.map +1 -1
- package/lib-es/network/node/ledger.d.ts +2 -1
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js +9 -10
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +3 -2
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +37 -29
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/staking/contracts.js +2 -2
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/fetchers.d.ts.map +1 -1
- package/lib-es/staking/fetchers.js +7 -7
- package/lib-es/staking/fetchers.js.map +1 -1
- package/lib-es/staking/prepareIntents.d.ts +2 -1
- package/lib-es/staking/prepareIntents.d.ts.map +1 -1
- package/lib-es/staking/prepareIntents.js +4 -4
- package/lib-es/staking/prepareIntents.js.map +1 -1
- package/lib-es/staking/redelegations.d.ts +5 -4
- package/lib-es/staking/redelegations.d.ts.map +1 -1
- package/lib-es/staking/redelegations.js +13 -14
- package/lib-es/staking/redelegations.js.map +1 -1
- package/lib-es/staking/rewards.d.ts +2 -1
- package/lib-es/staking/rewards.d.ts.map +1 -1
- package/lib-es/staking/rewards.js +4 -5
- package/lib-es/staking/rewards.js.map +1 -1
- package/lib-es/staking/rewardsFromReceipt.d.ts +2 -1
- package/lib-es/staking/rewardsFromReceipt.d.ts.map +1 -1
- package/lib-es/staking/rewardsFromReceipt.js +2 -3
- package/lib-es/staking/rewardsFromReceipt.js.map +1 -1
- package/lib-es/staking/unbondings.d.ts +2 -1
- package/lib-es/staking/unbondings.d.ts.map +1 -1
- package/lib-es/staking/unbondings.js +4 -5
- package/lib-es/staking/unbondings.js.map +1 -1
- package/lib-es/staking/validators/index.d.ts +9 -4
- package/lib-es/staking/validators/index.d.ts.map +1 -1
- package/lib-es/staking/validators/index.js +18 -10
- package/lib-es/staking/validators/index.js.map +1 -1
- package/lib-es/staking/validators/monad.d.ts +6 -5
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js +33 -29
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.d.ts +2 -1
- package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib-es/staking/validators/monadResolver.js +2 -3
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/staking/validators/somnia.d.ts +3 -2
- package/lib-es/staking/validators/somnia.d.ts.map +1 -1
- package/lib-es/staking/validators/somnia.js +16 -15
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/types.d.ts +2 -1
- package/lib-es/staking/validators/types.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.d.ts +2 -1
- package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js +7 -8
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/types/staking.d.ts +4 -3
- package/lib-es/types/staking.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/adapters/blockOperations.test.ts +86 -67
- package/src/adapters/blockOperations.ts +28 -17
- package/src/adapters/etherscan.test.ts +151 -85
- package/src/adapters/etherscan.ts +27 -18
- package/src/adapters/ledger.test.ts +210 -83
- package/src/adapters/ledger.ts +21 -15
- package/src/api/getBlock.integ.test.ts +10 -4
- package/src/api/index.arbitrum.integ.test.ts +1 -0
- package/src/api/index.arc.integ.test.ts +1 -0
- package/src/api/index.avalanche_c_chain_fuji.integ.test.ts +1 -0
- package/src/api/index.cronos.integ.test.ts +1 -0
- package/src/api/index.flare.integ.test.ts +4 -2
- package/src/api/index.integ.test.ts +7 -6
- package/src/api/index.linea.integ.test.ts +4 -2
- package/src/api/index.optimism.integ.test.ts +1 -0
- package/src/api/index.rsk.integ.test.ts +1 -0
- package/src/api/index.shape.integ.test.ts +4 -2
- package/src/api/index.somnia.integ.test.ts +1 -0
- package/src/api/index.test.ts +2 -2
- package/src/api/index.ts +1 -2
- package/src/config.ts +0 -1
- package/src/fixtures/context.fixtures.ts +5 -5
- package/src/logic/common.ts +1 -1
- package/src/logic/getBalance.ts +4 -3
- package/src/logic/getBlock.ts +43 -27
- package/src/logic/getStakes.ts +2 -1
- package/src/logic/internalTransactionsFetcher.ts +16 -10
- package/src/logic/listOperations.ts +2 -2
- package/src/logic/tests/getBalance.test.ts +5 -3
- package/src/logic/tests/getBlock.test.ts +16 -15
- package/src/logic/tests/internalTransactionsFetcher.test.ts +6 -5
- package/src/logic/tests/listOperations.test.ts +4 -4
- package/src/logic-public/tests/utils.test.ts +6 -5
- package/src/logic-public/utils.ts +8 -5
- package/src/logic.test.ts +5 -5
- package/src/network/explorer/etherscan.test.ts +169 -55
- package/src/network/explorer/etherscan.ts +27 -16
- package/src/network/explorer/index.test.ts +2 -1
- package/src/network/explorer/ledger.test.ts +208 -35
- package/src/network/explorer/ledger.ts +12 -8
- package/src/network/explorer/types.ts +3 -2
- package/src/network/node/explorerProxy.ts +3 -3
- package/src/network/node/index.ts +3 -2
- package/src/network/node/ledger.test.ts +25 -25
- package/src/network/node/ledger.ts +13 -10
- package/src/network/node/node.fixtures.ts +2 -1
- package/src/network/node/rpc.common.ts +84 -28
- package/src/network/node/rpc.test.ts +45 -31
- package/src/staking/contracts.ts +2 -2
- package/src/staking/fetchers.ts +20 -8
- package/src/staking/prepareIntents.test.ts +33 -12
- package/src/staking/prepareIntents.ts +9 -5
- package/src/staking/redelegations.test.ts +98 -35
- package/src/staking/redelegations.ts +20 -12
- package/src/staking/rewards.test.ts +15 -10
- package/src/staking/rewards.ts +8 -5
- package/src/staking/rewardsFromReceipt.test.ts +5 -4
- package/src/staking/rewardsFromReceipt.ts +4 -3
- package/src/staking/unbondings.test.ts +16 -12
- package/src/staking/unbondings.ts +7 -5
- package/src/staking/validators/index.ts +30 -10
- package/src/staking/validators/monad.test.ts +57 -43
- package/src/staking/validators/monad.ts +55 -32
- package/src/staking/validators/monadResolver.ts +4 -3
- package/src/staking/validators/somnia.test.ts +14 -13
- package/src/staking/validators/somnia.ts +35 -19
- package/src/staking/validators/types.ts +2 -0
- package/src/staking/validators/zero_gravity.test.ts +48 -26
- package/src/staking/validators/zero_gravity.ts +14 -8
- package/src/staking/validators.integ.test.ts +2 -2
- package/src/staking/validators.test.ts +31 -26
- package/src/types/staking.ts +9 -2
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import type { LogWithAddress } from '../network/node/types'
|
|
5
5
|
import type { RewardsEventDecoder } from '../types/staking'
|
|
6
6
|
import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
|
|
7
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
7
8
|
import { promiseAllBatched } from '@ledgerhq/coin-module-framework/promises'
|
|
8
|
-
import { log } from '@ledgerhq/logs'
|
|
9
9
|
import { STAKING_CONTRACTS } from './contracts'
|
|
10
10
|
|
|
11
11
|
/** Max in-flight receipt fetches, to avoid hammering the RPC node during sync. */
|
|
@@ -74,7 +74,8 @@ export function sumRewardFromReceiptLogs(
|
|
|
74
74
|
export async function enrichRewardOperationsValue(
|
|
75
75
|
currencyId: string,
|
|
76
76
|
operations: Array<Operation<MemoNotSupported>>,
|
|
77
|
-
getReceipt: ReceiptFetcher
|
|
77
|
+
getReceipt: ReceiptFetcher,
|
|
78
|
+
logger: Logger
|
|
78
79
|
): Promise<void> {
|
|
79
80
|
const decoder = STAKING_CONTRACTS[currencyId]?.rewardsEventDecoder
|
|
80
81
|
if (!decoder) {
|
|
@@ -97,7 +98,7 @@ export async function enrichRewardOperationsValue(
|
|
|
97
98
|
op.value = amount
|
|
98
99
|
}
|
|
99
100
|
} catch (e) {
|
|
100
|
-
|
|
101
|
+
logger('coin-evm/staking', 'enrichRewardOperationsValue: receipt fetch/decode failed', {
|
|
101
102
|
hash: op.tx.hash,
|
|
102
103
|
error: e instanceof Error ? e.message : String(e),
|
|
103
104
|
})
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import type { EvmConfigInfo } from '../config'
|
|
5
5
|
import type { DeepPartialCtor } from '@ledgerhq/coin-module-framework/test/utils'
|
|
6
6
|
import { ethers } from 'ethers'
|
|
7
|
+
import { testLogger } from '../fixtures/context.fixtures'
|
|
7
8
|
import { STAKING_CONTRACTS } from './contracts'
|
|
8
9
|
import { fetchUnbondings } from './unbondings'
|
|
9
10
|
import { USEI_TO_EVM_SCALE } from './utils'
|
|
@@ -30,6 +31,7 @@ const mockConfig: EvmConfigInfo = {
|
|
|
30
31
|
status: { type: 'active' },
|
|
31
32
|
chainId: 1329,
|
|
32
33
|
name: 'Sei',
|
|
34
|
+
unit: { name: 'sei', code: 'SEI', magnitude: 18 },
|
|
33
35
|
node: mockNode,
|
|
34
36
|
explorer: { type: 'none' },
|
|
35
37
|
}
|
|
@@ -78,35 +80,37 @@ describe('staking/unbondings', () => {
|
|
|
78
80
|
})
|
|
79
81
|
|
|
80
82
|
it('should return [] for an unknown currencyId', async () => {
|
|
81
|
-
expect(await fetchUnbondings(mockConfig, 'unknown_chain', EVM_ADDRESS)).toEqual(
|
|
83
|
+
expect(await fetchUnbondings(mockConfig, 'unknown_chain', EVM_ADDRESS, testLogger)).toEqual(
|
|
84
|
+
[]
|
|
85
|
+
)
|
|
82
86
|
expect(mockNetwork).not.toHaveBeenCalled()
|
|
83
87
|
})
|
|
84
88
|
|
|
85
89
|
it('should return [] for a currency without an unbonding strategy', async () => {
|
|
86
|
-
expect(await fetchUnbondings(mockConfig, 'celo', EVM_ADDRESS)).toEqual([])
|
|
90
|
+
expect(await fetchUnbondings(mockConfig, 'celo', EVM_ADDRESS, testLogger)).toEqual([])
|
|
87
91
|
expect(mockNetwork).not.toHaveBeenCalled()
|
|
88
92
|
})
|
|
89
93
|
|
|
90
94
|
it('should return [] when the address is not associated on-chain yet', async () => {
|
|
91
95
|
mockGetSeiAddr.mockResolvedValue(null)
|
|
92
|
-
expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)).toEqual([])
|
|
96
|
+
expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)).toEqual([])
|
|
93
97
|
expect(mockNetwork).not.toHaveBeenCalled()
|
|
94
98
|
})
|
|
95
99
|
|
|
96
100
|
it('should return [] when the REST call fails', async () => {
|
|
97
101
|
mockNetwork.mockRejectedValue(new Error('network error'))
|
|
98
|
-
expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)).toEqual([])
|
|
102
|
+
expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)).toEqual([])
|
|
99
103
|
})
|
|
100
104
|
|
|
101
105
|
it('should return [] when the response has no unbonding_responses array', async () => {
|
|
102
106
|
mockNetwork.mockResolvedValue({ data: {} })
|
|
103
|
-
expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)).toEqual([])
|
|
107
|
+
expect(await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)).toEqual([])
|
|
104
108
|
})
|
|
105
109
|
|
|
106
110
|
it('should query the delegator endpoint with the resolved Cosmos address', async () => {
|
|
107
111
|
mockNetwork.mockResolvedValue({ data: { unbonding_responses: [] } })
|
|
108
112
|
|
|
109
|
-
await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
|
|
113
|
+
await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
|
|
110
114
|
|
|
111
115
|
expect(mockNetwork).toHaveBeenCalledWith({
|
|
112
116
|
url: 'https://rest.sei-apis.com/cosmos/staking/v1beta1/delegators/sei1defaultcosmosaddressfortest/unbonding_delegations',
|
|
@@ -126,7 +130,7 @@ describe('staking/unbondings', () => {
|
|
|
126
130
|
},
|
|
127
131
|
})
|
|
128
132
|
|
|
129
|
-
const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
|
|
133
|
+
const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
|
|
130
134
|
|
|
131
135
|
expect(stakes).toHaveLength(1)
|
|
132
136
|
expect(stakes[0]).toMatchObject({
|
|
@@ -149,7 +153,7 @@ describe('staking/unbondings', () => {
|
|
|
149
153
|
},
|
|
150
154
|
})
|
|
151
155
|
|
|
152
|
-
const [stake] = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
|
|
156
|
+
const [stake] = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
|
|
153
157
|
|
|
154
158
|
// Sei credits the funds back automatically: no withdraw transaction exists.
|
|
155
159
|
expect(stake.actions).toEqual([])
|
|
@@ -168,7 +172,7 @@ describe('staking/unbondings', () => {
|
|
|
168
172
|
},
|
|
169
173
|
})
|
|
170
174
|
|
|
171
|
-
const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
|
|
175
|
+
const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
|
|
172
176
|
|
|
173
177
|
expect(stakes).toHaveLength(2)
|
|
174
178
|
expect(new Set(stakes.map((s) => s.uid)).size).toBe(2)
|
|
@@ -190,7 +194,7 @@ describe('staking/unbondings', () => {
|
|
|
190
194
|
},
|
|
191
195
|
})
|
|
192
196
|
|
|
193
|
-
const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
|
|
197
|
+
const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
|
|
194
198
|
|
|
195
199
|
expect(stakes.map((s) => s.delegate)).toEqual([VALIDATOR, OTHER_VALIDATOR])
|
|
196
200
|
})
|
|
@@ -207,7 +211,7 @@ describe('staking/unbondings', () => {
|
|
|
207
211
|
},
|
|
208
212
|
})
|
|
209
213
|
|
|
210
|
-
const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
|
|
214
|
+
const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
|
|
211
215
|
|
|
212
216
|
expect(stakes).toHaveLength(1)
|
|
213
217
|
expect(stakes[0].amount).toBe(2000000n * USEI_TO_EVM_SCALE)
|
|
@@ -227,7 +231,7 @@ describe('staking/unbondings', () => {
|
|
|
227
231
|
},
|
|
228
232
|
})
|
|
229
233
|
|
|
230
|
-
const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS)
|
|
234
|
+
const stakes = await fetchUnbondings(mockConfig, SEI_CURRENCY, EVM_ADDRESS, testLogger)
|
|
231
235
|
|
|
232
236
|
expect(stakes).toHaveLength(1)
|
|
233
237
|
expect(stakes[0].amount).toBe(3000000n * USEI_TO_EVM_SCALE)
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import type { EvmConfigInfo } from '../config'
|
|
5
5
|
import type { StakingContractConfig, UnbondingStrategy } from '../types/staking'
|
|
6
6
|
import type { Stake } from '@ledgerhq/coin-module-framework/api/types'
|
|
7
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
7
8
|
import network from '@ledgerhq/live-network'
|
|
8
|
-
import { log } from '@ledgerhq/logs'
|
|
9
9
|
import { evmUnit } from '../logic/evmUnit'
|
|
10
10
|
import { isExternalNodeConfig } from '../network/node/types'
|
|
11
11
|
import { STAKING_CONTRACTS } from './contracts'
|
|
@@ -35,7 +35,8 @@ async function fetchCosmosRestUnbondings(
|
|
|
35
35
|
config: StakingContractConfig,
|
|
36
36
|
strategy: Extract<UnbondingStrategy, { type: 'cosmos-rest' }>,
|
|
37
37
|
currencyId: string,
|
|
38
|
-
evmAddress: string
|
|
38
|
+
evmAddress: string,
|
|
39
|
+
logger: Logger
|
|
39
40
|
): Promise<Stake[]> {
|
|
40
41
|
const baseUrl = config.apiConfig?.baseUrl
|
|
41
42
|
const precompileAddress = config.apiConfig?.precompileAddress
|
|
@@ -55,7 +56,7 @@ async function fetchCosmosRestUnbondings(
|
|
|
55
56
|
const res = await network<UnbondingsApiResponse>({ url, method: 'GET' })
|
|
56
57
|
data = res.data
|
|
57
58
|
} catch (e) {
|
|
58
|
-
|
|
59
|
+
logger('coin-evm/staking', 'fetchCosmosRestUnbondings: REST request failed', {
|
|
59
60
|
url,
|
|
60
61
|
error: e instanceof Error ? e.message : String(e),
|
|
61
62
|
})
|
|
@@ -122,7 +123,8 @@ async function fetchCosmosRestUnbondings(
|
|
|
122
123
|
export async function fetchUnbondings(
|
|
123
124
|
evmConfig: EvmConfigInfo,
|
|
124
125
|
currencyId: string,
|
|
125
|
-
evmAddress: string
|
|
126
|
+
evmAddress: string,
|
|
127
|
+
logger: Logger
|
|
126
128
|
): Promise<Stake[]> {
|
|
127
129
|
const config = STAKING_CONTRACTS[currencyId]
|
|
128
130
|
const strategy = config?.unbondingStrategy
|
|
@@ -130,7 +132,7 @@ export async function fetchUnbondings(
|
|
|
130
132
|
|
|
131
133
|
switch (strategy.type) {
|
|
132
134
|
case 'cosmos-rest':
|
|
133
|
-
return fetchCosmosRestUnbondings(evmConfig, config, strategy, currencyId, evmAddress)
|
|
135
|
+
return fetchCosmosRestUnbondings(evmConfig, config, strategy, currencyId, evmAddress, logger)
|
|
134
136
|
default:
|
|
135
137
|
return []
|
|
136
138
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { EvmConfigInfo } from '../../config'
|
|
4
|
+
import type { EvmConfigInfo, EvmContext } from '../../config'
|
|
5
5
|
import type { ValidatorApi } from './types'
|
|
6
6
|
import type { Cursor, Page, Validator } from '@ledgerhq/coin-module-framework/api/index'
|
|
7
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
7
8
|
import { makeLRUCache } from '@ledgerhq/live-network/cache'
|
|
8
9
|
import { STAKING_CONTRACTS } from '../contracts'
|
|
9
10
|
import monadValidatorApi from './monad'
|
|
@@ -35,11 +36,12 @@ export const getValidatorApi = (currencyId: string): ValidatorApi | undefined =>
|
|
|
35
36
|
const resolveValidators = async (
|
|
36
37
|
config: EvmConfigInfo,
|
|
37
38
|
currencyId: string,
|
|
39
|
+
logger: Logger,
|
|
38
40
|
cursor?: Cursor
|
|
39
41
|
): Promise<Page<Validator>> => {
|
|
40
42
|
const api = getValidatorApi(currencyId)
|
|
41
43
|
if (!api) return { items: [], next: undefined }
|
|
42
|
-
return api.fetchValidators(config, currencyId, cursor)
|
|
44
|
+
return api.fetchValidators(config, currencyId, logger, cursor)
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
// One cache key per page, so each page of a paginated chain (e.g. Monad) is
|
|
@@ -49,10 +51,12 @@ const resolveValidators = async (
|
|
|
49
51
|
const pageKey = (currencyId: string, cursor?: Cursor): string => `${currencyId}-${cursor ?? ''}`
|
|
50
52
|
|
|
51
53
|
const validatorsCache = makeLRUCache(
|
|
52
|
-
(config: EvmConfigInfo, currencyId: string, cursor?: Cursor) =>
|
|
53
|
-
resolveValidators(config, currencyId, cursor),
|
|
54
|
-
// config
|
|
55
|
-
|
|
54
|
+
(config: EvmConfigInfo, currencyId: string, logger: Logger, cursor?: Cursor) =>
|
|
55
|
+
resolveValidators(config, currencyId, logger, cursor),
|
|
56
|
+
// config and logger are deterministic/side-channel per currency, so they are intentionally
|
|
57
|
+
// excluded from the cache key.
|
|
58
|
+
(_config: EvmConfigInfo, currencyId: string, _logger: Logger, cursor?: Cursor) =>
|
|
59
|
+
pageKey(currencyId, cursor),
|
|
56
60
|
{ max: 50, ttl: CACHE_MAX_AGE_MS }
|
|
57
61
|
)
|
|
58
62
|
|
|
@@ -80,13 +84,14 @@ export const clearValidatorsCache = (currencyId?: string): void => {
|
|
|
80
84
|
export const getValidators = async (
|
|
81
85
|
config: EvmConfigInfo,
|
|
82
86
|
currencyId: string,
|
|
87
|
+
logger: Logger,
|
|
83
88
|
cursor?: Cursor
|
|
84
89
|
): Promise<Page<Validator>> => {
|
|
85
90
|
const key = pageKey(currencyId, cursor)
|
|
86
91
|
issuedKeys.add(key)
|
|
87
92
|
|
|
88
93
|
try {
|
|
89
|
-
const page = await validatorsCache(config, currencyId, cursor)
|
|
94
|
+
const page = await validatorsCache(config, currencyId, logger, cursor)
|
|
90
95
|
// Never keep an empty page cached, so a transient empty response is retried next time.
|
|
91
96
|
if (page.items.length === 0) {
|
|
92
97
|
validatorsCache.clear(key)
|
|
@@ -106,8 +111,12 @@ export const getValidators = async (
|
|
|
106
111
|
* cache entry already returns without a network call, so repeated calls are cheap.
|
|
107
112
|
* Only the first page is warmed; subsequent pages are fetched lazily by the hook.
|
|
108
113
|
*/
|
|
109
|
-
export const prefetchValidators = (
|
|
110
|
-
|
|
114
|
+
export const prefetchValidators = (
|
|
115
|
+
config: EvmConfigInfo,
|
|
116
|
+
currencyId: string,
|
|
117
|
+
logger: Logger
|
|
118
|
+
): void => {
|
|
119
|
+
void getValidators(config, currencyId, logger).catch(() => {
|
|
111
120
|
/* swallow: the hook surfaces errors via its own flow */
|
|
112
121
|
})
|
|
113
122
|
}
|
|
@@ -148,4 +157,15 @@ export const hasChainRewards = (currencyId: string): boolean => {
|
|
|
148
157
|
return typeof config?.functions.claimReward === 'string'
|
|
149
158
|
}
|
|
150
159
|
|
|
151
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Public entry for a validators page: takes the instance-scoped {@link EvmContext} and
|
|
162
|
+
* resolves the currency config (and logger) from it, delegating to {@link getValidators}.
|
|
163
|
+
*/
|
|
164
|
+
export const getValidatorsPage = async (
|
|
165
|
+
context: EvmContext,
|
|
166
|
+
currencyId: string,
|
|
167
|
+
cursor?: Cursor
|
|
168
|
+
): Promise<Page<Validator>> => {
|
|
169
|
+
const config = await context.config(currencyId)
|
|
170
|
+
return getValidators(config, currencyId, context.logger, cursor)
|
|
171
|
+
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
createMockEvmConfigInfo,
|
|
12
12
|
mkExternalNode,
|
|
13
13
|
mkLedgerNode,
|
|
14
|
+
testLogger,
|
|
14
15
|
} from '../../fixtures/context.fixtures'
|
|
15
16
|
import { mkJsonRpcProvider } from '../../fixtures/ethers.fixtures'
|
|
16
17
|
import { withApi } from '../../network/node/rpc.common'
|
|
@@ -170,7 +171,7 @@ describe('staking/validators/monad', () => {
|
|
|
170
171
|
})
|
|
171
172
|
)
|
|
172
173
|
|
|
173
|
-
expect(await getValidators(mockConfig, 'monad')).toStrictEqual({
|
|
174
|
+
expect(await getValidators(mockConfig, 'monad', testLogger)).toStrictEqual({
|
|
174
175
|
items: [
|
|
175
176
|
{
|
|
176
177
|
id: '1',
|
|
@@ -199,7 +200,7 @@ describe('staking/validators/monad', () => {
|
|
|
199
200
|
|
|
200
201
|
// a non-empty page is cached: the second read makes no further RPC calls
|
|
201
202
|
const callsAfterFirst = callMock.mock.calls.length
|
|
202
|
-
await getValidators(mockConfig, 'monad')
|
|
203
|
+
await getValidators(mockConfig, 'monad', testLogger)
|
|
203
204
|
expect(callMock.mock.calls.length).toBe(callsAfterFirst)
|
|
204
205
|
})
|
|
205
206
|
|
|
@@ -221,7 +222,7 @@ describe('staking/validators/monad', () => {
|
|
|
221
222
|
status: 200,
|
|
222
223
|
})
|
|
223
224
|
|
|
224
|
-
const page = await getValidators(mockConfig, 'monad')
|
|
225
|
+
const page = await getValidators(mockConfig, 'monad', testLogger)
|
|
225
226
|
|
|
226
227
|
expect(page.items[0]).toMatchObject({
|
|
227
228
|
address: ethers.computeAddress(
|
|
@@ -253,7 +254,7 @@ describe('staking/validators/monad', () => {
|
|
|
253
254
|
})
|
|
254
255
|
)
|
|
255
256
|
|
|
256
|
-
const page = await getValidators(mockConfig, 'monad')
|
|
257
|
+
const page = await getValidators(mockConfig, 'monad', testLogger)
|
|
257
258
|
|
|
258
259
|
expect(page.items).toHaveLength(1)
|
|
259
260
|
expect(page.items[0]).toMatchObject({
|
|
@@ -272,19 +273,19 @@ describe('staking/validators/monad', () => {
|
|
|
272
273
|
})
|
|
273
274
|
)
|
|
274
275
|
|
|
275
|
-
const page = await getValidators(mockConfig, 'monad')
|
|
276
|
+
const page = await getValidators(mockConfig, 'monad', testLogger)
|
|
276
277
|
|
|
277
278
|
expect(page.items).toStrictEqual([])
|
|
278
279
|
expect(page.next).toBeUndefined()
|
|
279
280
|
|
|
280
281
|
// empty results are not cached, so the next read hits the precompile again
|
|
281
282
|
const callsAfterFirst = callMock.mock.calls.length
|
|
282
|
-
await getValidators(mockConfig, 'monad')
|
|
283
|
+
await getValidators(mockConfig, 'monad', testLogger)
|
|
283
284
|
expect(callMock.mock.calls.length).toBeGreaterThan(callsAfterFirst)
|
|
284
285
|
})
|
|
285
286
|
|
|
286
287
|
it('returns an empty page when the node config is not external', async () => {
|
|
287
|
-
const page = await getValidators(ledgerConfig, 'monad')
|
|
288
|
+
const page = await getValidators(ledgerConfig, 'monad', testLogger)
|
|
288
289
|
|
|
289
290
|
expect(page.items).toStrictEqual([])
|
|
290
291
|
expect(page.next).toBeUndefined()
|
|
@@ -300,7 +301,7 @@ describe('staking/validators/monad', () => {
|
|
|
300
301
|
})
|
|
301
302
|
)
|
|
302
303
|
|
|
303
|
-
const page = await getValidators(mockConfig, 'monad')
|
|
304
|
+
const page = await getValidators(mockConfig, 'monad', testLogger)
|
|
304
305
|
|
|
305
306
|
expect(page.items).toHaveLength(2)
|
|
306
307
|
expect(page.next).toBe('100')
|
|
@@ -317,10 +318,10 @@ describe('staking/validators/monad', () => {
|
|
|
317
318
|
})
|
|
318
319
|
)
|
|
319
320
|
|
|
320
|
-
const first = await getValidators(mockConfig, 'monad')
|
|
321
|
+
const first = await getValidators(mockConfig, 'monad', testLogger)
|
|
321
322
|
expect(first.next).toBe('100')
|
|
322
323
|
|
|
323
|
-
const second = await getValidators(mockConfig, 'monad', first.next)
|
|
324
|
+
const second = await getValidators(mockConfig, 'monad', testLogger, first.next)
|
|
324
325
|
expect(second.items).toHaveLength(1)
|
|
325
326
|
expect(second.next).toBeUndefined()
|
|
326
327
|
})
|
|
@@ -337,7 +338,7 @@ describe('staking/validators/monad', () => {
|
|
|
337
338
|
})
|
|
338
339
|
)
|
|
339
340
|
|
|
340
|
-
const page = await getValidators(mockConfig, 'monad')
|
|
341
|
+
const page = await getValidators(mockConfig, 'monad', testLogger)
|
|
341
342
|
|
|
342
343
|
expect(page.next).toBeUndefined()
|
|
343
344
|
})
|
|
@@ -352,10 +353,10 @@ describe('staking/validators/monad', () => {
|
|
|
352
353
|
})
|
|
353
354
|
)
|
|
354
355
|
|
|
355
|
-
await getValidators(mockConfig, 'monad')
|
|
356
|
+
await getValidators(mockConfig, 'monad', testLogger)
|
|
356
357
|
const callCountAfterFirst = callMock.mock.calls.length
|
|
357
358
|
|
|
358
|
-
const second = await getValidators(mockConfig, 'monad')
|
|
359
|
+
const second = await getValidators(mockConfig, 'monad', testLogger)
|
|
359
360
|
expect(second.items).toHaveLength(1)
|
|
360
361
|
expect(callMock.mock.calls.length).toBe(callCountAfterFirst)
|
|
361
362
|
})
|
|
@@ -371,8 +372,8 @@ describe('staking/validators/monad', () => {
|
|
|
371
372
|
})
|
|
372
373
|
)
|
|
373
374
|
|
|
374
|
-
const firstPage = await getValidators(mockConfig, 'monad')
|
|
375
|
-
const secondPage = await getValidators(mockConfig, 'monad', '100')
|
|
375
|
+
const firstPage = await getValidators(mockConfig, 'monad', testLogger)
|
|
376
|
+
const secondPage = await getValidators(mockConfig, 'monad', testLogger, '100')
|
|
376
377
|
const callsAfterBoth = callMock.mock.calls.length
|
|
377
378
|
|
|
378
379
|
expect(firstPage).toStrictEqual({
|
|
@@ -393,8 +394,8 @@ describe('staking/validators/monad', () => {
|
|
|
393
394
|
expect(secondPage.next).toBeUndefined()
|
|
394
395
|
|
|
395
396
|
// both cursors are now cached independently — no further RPC calls
|
|
396
|
-
expect(await getValidators(mockConfig, 'monad')).toStrictEqual(firstPage)
|
|
397
|
-
expect(await getValidators(mockConfig, 'monad', '100')).toStrictEqual(secondPage)
|
|
397
|
+
expect(await getValidators(mockConfig, 'monad', testLogger)).toStrictEqual(firstPage)
|
|
398
|
+
expect(await getValidators(mockConfig, 'monad', testLogger, '100')).toStrictEqual(secondPage)
|
|
398
399
|
expect(callMock.mock.calls.length).toBe(callsAfterBoth)
|
|
399
400
|
})
|
|
400
401
|
|
|
@@ -409,15 +410,15 @@ describe('staking/validators/monad', () => {
|
|
|
409
410
|
})
|
|
410
411
|
)
|
|
411
412
|
|
|
412
|
-
await getValidators(mockConfig, 'monad')
|
|
413
|
-
await getValidators(mockConfig, 'monad', '100')
|
|
413
|
+
await getValidators(mockConfig, 'monad', testLogger)
|
|
414
|
+
await getValidators(mockConfig, 'monad', testLogger, '100')
|
|
414
415
|
const callsBeforeClear = callMock.mock.calls.length
|
|
415
416
|
|
|
416
417
|
clearValidatorsCache('monad')
|
|
417
418
|
|
|
418
419
|
// every cursor was evicted, so both reads hit the precompile again
|
|
419
|
-
await getValidators(mockConfig, 'monad')
|
|
420
|
-
await getValidators(mockConfig, 'monad', '100')
|
|
420
|
+
await getValidators(mockConfig, 'monad', testLogger)
|
|
421
|
+
await getValidators(mockConfig, 'monad', testLogger, '100')
|
|
421
422
|
expect(callMock.mock.calls.length).toBeGreaterThan(callsBeforeClear)
|
|
422
423
|
})
|
|
423
424
|
})
|
|
@@ -435,7 +436,7 @@ describe('staking/validators/monad', () => {
|
|
|
435
436
|
})
|
|
436
437
|
)
|
|
437
438
|
|
|
438
|
-
expect(await getValidatorAddressById(mockConfig, 'monad', 7n)).toEqual(
|
|
439
|
+
expect(await getValidatorAddressById(mockConfig, 'monad', 7n, testLogger)).toEqual(
|
|
439
440
|
ethers.computeAddress(
|
|
440
441
|
'0x036e44a092493800e427b2b08d3427d804348b1368ecd0a6af6510ae40ce507187'
|
|
441
442
|
)
|
|
@@ -443,13 +444,13 @@ describe('staking/validators/monad', () => {
|
|
|
443
444
|
})
|
|
444
445
|
|
|
445
446
|
it('returns null when the node config is not external', async () => {
|
|
446
|
-
expect(await getValidatorAddressById(ledgerConfig, 'monad', 7n)).toBeNull()
|
|
447
|
+
expect(await getValidatorAddressById(ledgerConfig, 'monad', 7n, testLogger)).toBeNull()
|
|
447
448
|
})
|
|
448
449
|
|
|
449
450
|
it('returns null when the getValidator call fails', async () => {
|
|
450
451
|
setupRpc(routeByName({ getValidator: () => new Error('boom') }))
|
|
451
452
|
|
|
452
|
-
expect(await getValidatorAddressById(mockConfig, 'monad', 7n)).toBeNull()
|
|
453
|
+
expect(await getValidatorAddressById(mockConfig, 'monad', 7n, testLogger)).toBeNull()
|
|
453
454
|
})
|
|
454
455
|
})
|
|
455
456
|
|
|
@@ -465,7 +466,7 @@ describe('staking/validators/monad', () => {
|
|
|
465
466
|
}
|
|
466
467
|
|
|
467
468
|
const fetchStakes = (config: EvmConfigInfo = mockConfig) =>
|
|
468
|
-
fetchMonadStakes(config, DELEGATOR, dummyStakingConfig, 'monad')
|
|
469
|
+
fetchMonadStakes(config, DELEGATOR, dummyStakingConfig, 'monad', testLogger)
|
|
469
470
|
|
|
470
471
|
const encodeDelegator = (
|
|
471
472
|
stake: bigint,
|
|
@@ -855,9 +856,14 @@ describe('staking/validators/monad', () => {
|
|
|
855
856
|
})
|
|
856
857
|
)
|
|
857
858
|
|
|
858
|
-
const stakes = await fetchMonadStakes(
|
|
859
|
-
|
|
860
|
-
|
|
859
|
+
const stakes = await fetchMonadStakes(
|
|
860
|
+
mockConfig,
|
|
861
|
+
DELEGATOR,
|
|
862
|
+
dummyStakingConfig,
|
|
863
|
+
'monad',
|
|
864
|
+
testLogger,
|
|
865
|
+
['92']
|
|
866
|
+
)
|
|
861
867
|
|
|
862
868
|
const withdrawal = stakes.find((s) => s.details?.validatorId === '92')
|
|
863
869
|
expect(withdrawal).toMatchObject({
|
|
@@ -880,9 +886,14 @@ describe('staking/validators/monad', () => {
|
|
|
880
886
|
})
|
|
881
887
|
)
|
|
882
888
|
|
|
883
|
-
const stakes = await fetchMonadStakes(
|
|
884
|
-
|
|
885
|
-
|
|
889
|
+
const stakes = await fetchMonadStakes(
|
|
890
|
+
mockConfig,
|
|
891
|
+
DELEGATOR,
|
|
892
|
+
dummyStakingConfig,
|
|
893
|
+
'monad',
|
|
894
|
+
testLogger,
|
|
895
|
+
['7']
|
|
896
|
+
)
|
|
886
897
|
|
|
887
898
|
expect(stakes).toHaveLength(1)
|
|
888
899
|
expect(delegatorCallCount).toBe(1)
|
|
@@ -912,47 +923,50 @@ describe('staking/validators/monad', () => {
|
|
|
912
923
|
|
|
913
924
|
it('extracts a validator id from a DELEGATE op', () => {
|
|
914
925
|
const payload = monadIface.encodeFunctionData('delegate', [42n])
|
|
915
|
-
expect(
|
|
926
|
+
expect(
|
|
927
|
+
extractMonadKnownValIds('monad', [makeOp('DELEGATE', payload)], testLogger)
|
|
928
|
+
).toStrictEqual(['42'])
|
|
916
929
|
})
|
|
917
930
|
|
|
918
931
|
it('extracts a validator id from an UNDELEGATE op', () => {
|
|
919
932
|
const payload = monadIface.encodeFunctionData('undelegate', [92n, 10_000_000_000n, 0n])
|
|
920
|
-
expect(
|
|
921
|
-
'
|
|
922
|
-
])
|
|
933
|
+
expect(
|
|
934
|
+
extractMonadKnownValIds('monad', [makeOp('UNDELEGATE', payload)], testLogger)
|
|
935
|
+
).toStrictEqual(['92'])
|
|
923
936
|
})
|
|
924
937
|
|
|
925
938
|
it('extracts a validator id from a WITHDRAW_UNBONDED op', () => {
|
|
926
939
|
const payload = monadIface.encodeFunctionData('withdraw', [7n, 3n])
|
|
927
940
|
expect(
|
|
928
|
-
extractMonadKnownValIds('monad', [makeOp('WITHDRAW_UNBONDED', payload)])
|
|
941
|
+
extractMonadKnownValIds('monad', [makeOp('WITHDRAW_UNBONDED', payload)], testLogger)
|
|
929
942
|
).toStrictEqual(['7'])
|
|
930
943
|
})
|
|
931
944
|
|
|
932
945
|
it('deduplicates repeated validator ids across multiple ops', () => {
|
|
933
946
|
const p1 = monadIface.encodeFunctionData('undelegate', [92n, 5_000_000_000n, 0n])
|
|
934
947
|
const p2 = monadIface.encodeFunctionData('undelegate', [92n, 5_000_000_000n, 1n])
|
|
935
|
-
const result = extractMonadKnownValIds(
|
|
936
|
-
|
|
937
|
-
makeOp('UNDELEGATE', p2),
|
|
938
|
-
|
|
948
|
+
const result = extractMonadKnownValIds(
|
|
949
|
+
'monad',
|
|
950
|
+
[makeOp('UNDELEGATE', p1), makeOp('UNDELEGATE', p2)],
|
|
951
|
+
testLogger
|
|
952
|
+
)
|
|
939
953
|
expect(result).toStrictEqual(['92'])
|
|
940
954
|
})
|
|
941
955
|
|
|
942
956
|
it('ignores ops whose type is not a staking function', () => {
|
|
943
|
-
const result = extractMonadKnownValIds('monad', [makeOp('OUT'), makeOp('IN')])
|
|
957
|
+
const result = extractMonadKnownValIds('monad', [makeOp('OUT'), makeOp('IN')], testLogger)
|
|
944
958
|
expect(result).toStrictEqual([])
|
|
945
959
|
})
|
|
946
960
|
|
|
947
961
|
it('skips ops with no contractPayload without throwing', () => {
|
|
948
|
-
const result = extractMonadKnownValIds('monad', [makeOp('UNDELEGATE')])
|
|
962
|
+
const result = extractMonadKnownValIds('monad', [makeOp('UNDELEGATE')], testLogger)
|
|
949
963
|
expect(result).toStrictEqual([])
|
|
950
964
|
})
|
|
951
965
|
|
|
952
966
|
it('returns an empty array for an unknown currencyId (no ABI available)', () => {
|
|
953
967
|
const payload = monadIface.encodeFunctionData('undelegate', [7n, 1n, 0n])
|
|
954
968
|
expect(
|
|
955
|
-
extractMonadKnownValIds('unknown_coin', [makeOp('UNDELEGATE', payload)])
|
|
969
|
+
extractMonadKnownValIds('unknown_coin', [makeOp('UNDELEGATE', payload)], testLogger)
|
|
956
970
|
).toStrictEqual([])
|
|
957
971
|
})
|
|
958
972
|
})
|