@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
|
@@ -6,6 +6,7 @@ import type { OperationLike } from './redelegations'
|
|
|
6
6
|
import type { DeepPartialCtor } from '@ledgerhq/coin-module-framework/test/utils'
|
|
7
7
|
import { BigNumber } from 'bignumber.js'
|
|
8
8
|
import { ethers } from 'ethers'
|
|
9
|
+
import { testLogger } from '../fixtures/context.fixtures'
|
|
9
10
|
import { getStakingABI } from './abis'
|
|
10
11
|
import { STAKING_CONTRACTS } from './contracts'
|
|
11
12
|
import {
|
|
@@ -93,11 +94,11 @@ describe('redelegations', () => {
|
|
|
93
94
|
})
|
|
94
95
|
|
|
95
96
|
it('should return [] for an unknown currencyId', async () => {
|
|
96
|
-
expect(await fetchRedelegations(mockConfig, 'unknown_chain', '0xabc')).toEqual([])
|
|
97
|
+
expect(await fetchRedelegations(mockConfig, 'unknown_chain', '0xabc', testLogger)).toEqual([])
|
|
97
98
|
})
|
|
98
99
|
|
|
99
100
|
it("should return [] when the strategy type is 'none'", async () => {
|
|
100
|
-
expect(await fetchRedelegations(mockConfig, 'celo', '0xabc')).toEqual([])
|
|
101
|
+
expect(await fetchRedelegations(mockConfig, 'celo', '0xabc', testLogger)).toEqual([])
|
|
101
102
|
})
|
|
102
103
|
|
|
103
104
|
it('should return [] when the network call fails', async () => {
|
|
@@ -106,7 +107,8 @@ describe('redelegations', () => {
|
|
|
106
107
|
await fetchRedelegations(
|
|
107
108
|
mockConfig,
|
|
108
109
|
'sei_evm',
|
|
109
|
-
'0x1234567890abcdef1234567890abcdef12345678'
|
|
110
|
+
'0x1234567890abcdef1234567890abcdef12345678',
|
|
111
|
+
testLogger
|
|
110
112
|
)
|
|
111
113
|
).toEqual([])
|
|
112
114
|
})
|
|
@@ -117,7 +119,8 @@ describe('redelegations', () => {
|
|
|
117
119
|
await fetchRedelegations(
|
|
118
120
|
mockConfig,
|
|
119
121
|
'sei_evm',
|
|
120
|
-
'0x1234567890abcdef1234567890abcdef12345678'
|
|
122
|
+
'0x1234567890abcdef1234567890abcdef12345678',
|
|
123
|
+
testLogger
|
|
121
124
|
)
|
|
122
125
|
).toEqual([])
|
|
123
126
|
})
|
|
@@ -149,7 +152,8 @@ describe('redelegations', () => {
|
|
|
149
152
|
await fetchRedelegations(
|
|
150
153
|
mockConfig,
|
|
151
154
|
'sei_evm',
|
|
152
|
-
'0x1234567890abcdef1234567890abcdef12345678'
|
|
155
|
+
'0x1234567890abcdef1234567890abcdef12345678',
|
|
156
|
+
testLogger
|
|
153
157
|
)
|
|
154
158
|
).toEqual([])
|
|
155
159
|
})
|
|
@@ -180,7 +184,8 @@ describe('redelegations', () => {
|
|
|
180
184
|
const result = await fetchRedelegations(
|
|
181
185
|
mockConfig,
|
|
182
186
|
'sei_evm',
|
|
183
|
-
'0x1234567890abcdef1234567890abcdef12345678'
|
|
187
|
+
'0x1234567890abcdef1234567890abcdef12345678',
|
|
188
|
+
testLogger
|
|
184
189
|
)
|
|
185
190
|
expect(result).toHaveLength(1)
|
|
186
191
|
expect(result[0].validatorSrcAddress).toBe('seivaloper1src')
|
|
@@ -201,7 +206,7 @@ describe('redelegations', () => {
|
|
|
201
206
|
mockGetSeiAddr.mockResolvedValueOnce(canonicalCosmosAddress)
|
|
202
207
|
mockNetwork.mockResolvedValueOnce({ data: { redelegation_responses: [] } })
|
|
203
208
|
|
|
204
|
-
await fetchRedelegations(mockConfig, 'sei_evm', evmAddress)
|
|
209
|
+
await fetchRedelegations(mockConfig, 'sei_evm', evmAddress, testLogger)
|
|
205
210
|
|
|
206
211
|
expect(mockNetwork).toHaveBeenCalledTimes(1)
|
|
207
212
|
expect(mockNetwork).toHaveBeenCalledWith(
|
|
@@ -220,7 +225,8 @@ describe('redelegations', () => {
|
|
|
220
225
|
await fetchRedelegations(
|
|
221
226
|
mockConfig,
|
|
222
227
|
'sei_evm',
|
|
223
|
-
'0x66c4371aE8FFeD2ec1c2EBbbcCfb7E494181E1E3'
|
|
228
|
+
'0x66c4371aE8FFeD2ec1c2EBbbcCfb7E494181E1E3',
|
|
229
|
+
testLogger
|
|
224
230
|
)
|
|
225
231
|
).toEqual([])
|
|
226
232
|
expect(mockNetwork).not.toHaveBeenCalled()
|
|
@@ -239,7 +245,7 @@ describe('redelegations', () => {
|
|
|
239
245
|
const calldata = encodeRedelegateCalldata(SRC, DST, AMOUNT_USEI)
|
|
240
246
|
const op = makeOperation({ type: 'REDELEGATE', extra: { contractPayload: calldata } })
|
|
241
247
|
|
|
242
|
-
const result = await resolveRedelegationValidators(mockConfig, SEI_CURRENCY, op)
|
|
248
|
+
const result = await resolveRedelegationValidators(mockConfig, SEI_CURRENCY, op, testLogger)
|
|
243
249
|
|
|
244
250
|
expect(result).toMatchObject({
|
|
245
251
|
srcValidatorAddress: SRC,
|
|
@@ -259,7 +265,8 @@ describe('redelegations', () => {
|
|
|
259
265
|
const result = await resolveRedelegationValidators(
|
|
260
266
|
mockConfig,
|
|
261
267
|
SEI_CURRENCY,
|
|
262
|
-
makeOperation({ type: 'REDELEGATE', extra: {} })
|
|
268
|
+
makeOperation({ type: 'REDELEGATE', extra: {} }),
|
|
269
|
+
testLogger
|
|
263
270
|
)
|
|
264
271
|
|
|
265
272
|
expect(result).toMatchObject({
|
|
@@ -275,7 +282,8 @@ describe('redelegations', () => {
|
|
|
275
282
|
const result = await resolveRedelegationValidators(
|
|
276
283
|
mockConfig,
|
|
277
284
|
SEI_CURRENCY,
|
|
278
|
-
makeOperation({ type: 'REDELEGATE', extra: {} })
|
|
285
|
+
makeOperation({ type: 'REDELEGATE', extra: {} }),
|
|
286
|
+
testLogger
|
|
279
287
|
)
|
|
280
288
|
expect(result).toBeNull()
|
|
281
289
|
})
|
|
@@ -285,12 +293,16 @@ describe('redelegations', () => {
|
|
|
285
293
|
type: 'REDELEGATE',
|
|
286
294
|
extra: { contractPayload: encodeRedelegateCalldata(SRC, DST, AMOUNT_USEI) },
|
|
287
295
|
})
|
|
288
|
-
expect(
|
|
296
|
+
expect(
|
|
297
|
+
await resolveRedelegationValidators(mockConfig, 'unsupported', op, testLogger)
|
|
298
|
+
).toBeNull()
|
|
289
299
|
})
|
|
290
300
|
|
|
291
301
|
it('should return null for malformed calldata', async () => {
|
|
292
302
|
const op = makeOperation({ type: 'REDELEGATE', extra: { contractPayload: '0xdeadbeef' } })
|
|
293
|
-
expect(
|
|
303
|
+
expect(
|
|
304
|
+
await resolveRedelegationValidators(mockConfig, SEI_CURRENCY, op, testLogger)
|
|
305
|
+
).toBeNull()
|
|
294
306
|
})
|
|
295
307
|
})
|
|
296
308
|
|
|
@@ -306,7 +318,9 @@ describe('redelegations', () => {
|
|
|
306
318
|
type: 'DELEGATE',
|
|
307
319
|
extra: { contractPayload: encodeDelegateCalldata(VALIDATOR) },
|
|
308
320
|
})
|
|
309
|
-
expect(
|
|
321
|
+
expect(
|
|
322
|
+
await resolveStakingValidator(mockConfig, 'unsupported', op, 'delegate', testLogger)
|
|
323
|
+
).toBeNull()
|
|
310
324
|
})
|
|
311
325
|
|
|
312
326
|
describe('delegate (Monad, id-keyed validatorId)', () => {
|
|
@@ -339,7 +353,13 @@ describe('redelegations', () => {
|
|
|
339
353
|
})
|
|
340
354
|
)
|
|
341
355
|
|
|
342
|
-
const result = await resolveStakingValidator(
|
|
356
|
+
const result = await resolveStakingValidator(
|
|
357
|
+
mockConfig,
|
|
358
|
+
'monad',
|
|
359
|
+
op,
|
|
360
|
+
'delegate',
|
|
361
|
+
testLogger
|
|
362
|
+
)
|
|
343
363
|
|
|
344
364
|
expect(result).toMatchObject({
|
|
345
365
|
validatorAddress: ethers.computeAddress(
|
|
@@ -361,7 +381,13 @@ describe('redelegations', () => {
|
|
|
361
381
|
},
|
|
362
382
|
})
|
|
363
383
|
|
|
364
|
-
const result = await resolveStakingValidator(
|
|
384
|
+
const result = await resolveStakingValidator(
|
|
385
|
+
mockConfig,
|
|
386
|
+
'zero_gravity',
|
|
387
|
+
op,
|
|
388
|
+
'delegate',
|
|
389
|
+
testLogger
|
|
390
|
+
)
|
|
365
391
|
|
|
366
392
|
expect(result).toMatchObject({
|
|
367
393
|
validatorAddress: '0x2222222222222222222222222222222222222222',
|
|
@@ -404,7 +430,13 @@ describe('redelegations', () => {
|
|
|
404
430
|
})
|
|
405
431
|
)
|
|
406
432
|
|
|
407
|
-
const result = await resolveStakingValidator(
|
|
433
|
+
const result = await resolveStakingValidator(
|
|
434
|
+
zgConfig,
|
|
435
|
+
'zero_gravity',
|
|
436
|
+
op,
|
|
437
|
+
'undelegate',
|
|
438
|
+
testLogger
|
|
439
|
+
)
|
|
408
440
|
|
|
409
441
|
expect(result).toEqual({
|
|
410
442
|
validatorAddress: '0x3333333333333333333333333333333333333333',
|
|
@@ -420,7 +452,13 @@ describe('redelegations', () => {
|
|
|
420
452
|
extra: { contractPayload: encodeDelegateCalldata(VALIDATOR) },
|
|
421
453
|
})
|
|
422
454
|
|
|
423
|
-
const result = await resolveStakingValidator(
|
|
455
|
+
const result = await resolveStakingValidator(
|
|
456
|
+
mockConfig,
|
|
457
|
+
SEI_CURRENCY,
|
|
458
|
+
op,
|
|
459
|
+
'delegate',
|
|
460
|
+
testLogger
|
|
461
|
+
)
|
|
424
462
|
|
|
425
463
|
expect(result).toMatchObject({ validatorAddress: VALIDATOR })
|
|
426
464
|
})
|
|
@@ -436,7 +474,8 @@ describe('redelegations', () => {
|
|
|
436
474
|
mockConfig,
|
|
437
475
|
SEI_CURRENCY,
|
|
438
476
|
makeOperation({ type: 'DELEGATE', extra: {} }),
|
|
439
|
-
'delegate'
|
|
477
|
+
'delegate',
|
|
478
|
+
testLogger
|
|
440
479
|
)
|
|
441
480
|
|
|
442
481
|
expect(result).toMatchObject({ validatorAddress: VALIDATOR })
|
|
@@ -450,7 +489,8 @@ describe('redelegations', () => {
|
|
|
450
489
|
mockConfig,
|
|
451
490
|
SEI_CURRENCY,
|
|
452
491
|
makeOperation({ type: 'DELEGATE', extra: {} }),
|
|
453
|
-
'delegate'
|
|
492
|
+
'delegate',
|
|
493
|
+
testLogger
|
|
454
494
|
)
|
|
455
495
|
).toBeNull()
|
|
456
496
|
})
|
|
@@ -463,7 +503,13 @@ describe('redelegations', () => {
|
|
|
463
503
|
extra: { contractPayload: encodeUndelegateCalldata(VALIDATOR, AMOUNT_USEI) },
|
|
464
504
|
})
|
|
465
505
|
|
|
466
|
-
const result = await resolveStakingValidator(
|
|
506
|
+
const result = await resolveStakingValidator(
|
|
507
|
+
mockConfig,
|
|
508
|
+
SEI_CURRENCY,
|
|
509
|
+
op,
|
|
510
|
+
'undelegate',
|
|
511
|
+
testLogger
|
|
512
|
+
)
|
|
467
513
|
|
|
468
514
|
expect(result).toMatchObject({ validatorAddress: VALIDATOR })
|
|
469
515
|
expect(result!.amount?.isEqualTo(EXPECTED_WEI.toString())).toBe(true)
|
|
@@ -484,7 +530,8 @@ describe('redelegations', () => {
|
|
|
484
530
|
mockConfig,
|
|
485
531
|
SEI_CURRENCY,
|
|
486
532
|
makeOperation({ type: 'UNDELEGATE', extra: {} }),
|
|
487
|
-
'undelegate'
|
|
533
|
+
'undelegate',
|
|
534
|
+
testLogger
|
|
488
535
|
)
|
|
489
536
|
|
|
490
537
|
expect(result).toMatchObject({ validatorAddress: VALIDATOR })
|
|
@@ -495,7 +542,9 @@ describe('redelegations', () => {
|
|
|
495
542
|
type: 'UNDELEGATE',
|
|
496
543
|
extra: { contractPayload: '0xdeadbeef' },
|
|
497
544
|
})
|
|
498
|
-
expect(
|
|
545
|
+
expect(
|
|
546
|
+
await resolveStakingValidator(mockConfig, SEI_CURRENCY, op, 'undelegate', testLogger)
|
|
547
|
+
).toBeNull()
|
|
499
548
|
})
|
|
500
549
|
})
|
|
501
550
|
})
|
|
@@ -510,14 +559,17 @@ describe('redelegations', () => {
|
|
|
510
559
|
beforeEach(() => jest.clearAllMocks())
|
|
511
560
|
|
|
512
561
|
it('should return [] for an unsupported currencyId', async () => {
|
|
513
|
-
expect(await buildRedelegationsFromOps(mockConfig, 'unsupported', [])).toEqual([])
|
|
562
|
+
expect(await buildRedelegationsFromOps(mockConfig, 'unsupported', [], testLogger)).toEqual([])
|
|
514
563
|
})
|
|
515
564
|
|
|
516
565
|
it('should ignore non-REDELEGATE operations', async () => {
|
|
517
566
|
expect(
|
|
518
|
-
await buildRedelegationsFromOps(
|
|
519
|
-
|
|
520
|
-
|
|
567
|
+
await buildRedelegationsFromOps(
|
|
568
|
+
mockConfig,
|
|
569
|
+
SEI_CURRENCY,
|
|
570
|
+
[makeOperation({ type: 'DELEGATE' })],
|
|
571
|
+
testLogger
|
|
572
|
+
)
|
|
521
573
|
).toEqual([])
|
|
522
574
|
})
|
|
523
575
|
|
|
@@ -528,7 +580,9 @@ describe('redelegations', () => {
|
|
|
528
580
|
extra: { contractPayload: encodeRedelegateCalldata(SRC, DST, AMOUNT_USEI) },
|
|
529
581
|
date: new Date(),
|
|
530
582
|
})
|
|
531
|
-
expect(await buildRedelegationsFromOps(mockConfig, SEI_CURRENCY, [op])).toEqual(
|
|
583
|
+
expect(await buildRedelegationsFromOps(mockConfig, SEI_CURRENCY, [op], testLogger)).toEqual(
|
|
584
|
+
[]
|
|
585
|
+
)
|
|
532
586
|
})
|
|
533
587
|
|
|
534
588
|
it('should ignore operations whose unbonding period has already elapsed', async () => {
|
|
@@ -537,7 +591,9 @@ describe('redelegations', () => {
|
|
|
537
591
|
extra: { contractPayload: encodeRedelegateCalldata(SRC, DST, AMOUNT_USEI) },
|
|
538
592
|
date: new Date(Date.now() - unbondingMs - 1000),
|
|
539
593
|
})
|
|
540
|
-
expect(await buildRedelegationsFromOps(mockConfig, SEI_CURRENCY, [op])).toEqual(
|
|
594
|
+
expect(await buildRedelegationsFromOps(mockConfig, SEI_CURRENCY, [op], testLogger)).toEqual(
|
|
595
|
+
[]
|
|
596
|
+
)
|
|
541
597
|
})
|
|
542
598
|
|
|
543
599
|
it('should build a redelegation from a recent REDELEGATE op with cached calldata', async () => {
|
|
@@ -547,7 +603,7 @@ describe('redelegations', () => {
|
|
|
547
603
|
date: new Date(),
|
|
548
604
|
})
|
|
549
605
|
|
|
550
|
-
const result = await buildRedelegationsFromOps(mockConfig, SEI_CURRENCY, [op])
|
|
606
|
+
const result = await buildRedelegationsFromOps(mockConfig, SEI_CURRENCY, [op], testLogger)
|
|
551
607
|
|
|
552
608
|
expect(result).toHaveLength(1)
|
|
553
609
|
expect(result[0]).toMatchObject({
|
|
@@ -568,9 +624,12 @@ describe('redelegations', () => {
|
|
|
568
624
|
})
|
|
569
625
|
)
|
|
570
626
|
|
|
571
|
-
const result = await buildRedelegationsFromOps(
|
|
572
|
-
|
|
573
|
-
|
|
627
|
+
const result = await buildRedelegationsFromOps(
|
|
628
|
+
mockConfig,
|
|
629
|
+
SEI_CURRENCY,
|
|
630
|
+
[makeOperation({ type: 'REDELEGATE', extra: {}, date: new Date() })],
|
|
631
|
+
testLogger
|
|
632
|
+
)
|
|
574
633
|
|
|
575
634
|
expect(result).toHaveLength(1)
|
|
576
635
|
expect(result[0].validatorSrcAddress).toBe(SRC)
|
|
@@ -582,7 +641,9 @@ describe('redelegations', () => {
|
|
|
582
641
|
extra: { contractPayload: '0xdeadbeef' },
|
|
583
642
|
date: new Date(),
|
|
584
643
|
})
|
|
585
|
-
expect(await buildRedelegationsFromOps(mockConfig, SEI_CURRENCY, [op])).toEqual(
|
|
644
|
+
expect(await buildRedelegationsFromOps(mockConfig, SEI_CURRENCY, [op], testLogger)).toEqual(
|
|
645
|
+
[]
|
|
646
|
+
)
|
|
586
647
|
})
|
|
587
648
|
|
|
588
649
|
it('should process multiple operations correctly', async () => {
|
|
@@ -599,7 +660,7 @@ describe('redelegations', () => {
|
|
|
599
660
|
}),
|
|
600
661
|
]
|
|
601
662
|
|
|
602
|
-
const result = await buildRedelegationsFromOps(mockConfig, SEI_CURRENCY, ops)
|
|
663
|
+
const result = await buildRedelegationsFromOps(mockConfig, SEI_CURRENCY, ops, testLogger)
|
|
603
664
|
expect(result).toHaveLength(2)
|
|
604
665
|
expect(result[0].validatorSrcAddress).toBe(SRC)
|
|
605
666
|
expect(result[1].validatorSrcAddress).toBe(DST)
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import type { EvmConfigInfo } from '../config'
|
|
5
5
|
import type { RedelegationStrategy } from '../types/staking'
|
|
6
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
6
7
|
import network from '@ledgerhq/live-network'
|
|
7
|
-
import { log } from '@ledgerhq/logs'
|
|
8
8
|
import { BigNumber } from 'bignumber.js'
|
|
9
9
|
import { ethers } from 'ethers'
|
|
10
10
|
import { withApi } from '../network/node/rpc.common'
|
|
@@ -108,6 +108,7 @@ async function fetchCosmosRestRedelegations(
|
|
|
108
108
|
strategy: Extract<RedelegationStrategy, { type: 'cosmos-rest' }>,
|
|
109
109
|
evmAddress: string,
|
|
110
110
|
calldataAmountScale: bigint,
|
|
111
|
+
logger: Logger,
|
|
111
112
|
evmRpcUrl?: string,
|
|
112
113
|
precompileAddress?: { address: string; abi: string }
|
|
113
114
|
): Promise<EvmRedelegation[]> {
|
|
@@ -121,7 +122,7 @@ async function fetchCosmosRestRedelegations(
|
|
|
121
122
|
const res = await network<CosmosRedelegationsApiResponse>({ url, method: 'GET' })
|
|
122
123
|
data = res.data
|
|
123
124
|
} catch (e) {
|
|
124
|
-
|
|
125
|
+
logger('coin-evm/staking', 'fetchCosmosRestRedelegations: REST request failed', {
|
|
125
126
|
url,
|
|
126
127
|
error: e instanceof Error ? e.message : String(e),
|
|
127
128
|
})
|
|
@@ -167,7 +168,8 @@ async function fetchCosmosRestRedelegations(
|
|
|
167
168
|
export async function fetchRedelegations(
|
|
168
169
|
evmConfig: EvmConfigInfo,
|
|
169
170
|
currencyId: string,
|
|
170
|
-
evmAddress: string
|
|
171
|
+
evmAddress: string,
|
|
172
|
+
logger: Logger
|
|
171
173
|
): Promise<EvmRedelegation[]> {
|
|
172
174
|
const config = STAKING_CONTRACTS[currencyId]
|
|
173
175
|
const strategy = config?.redelegationStrategy
|
|
@@ -183,6 +185,7 @@ export async function fetchRedelegations(
|
|
|
183
185
|
strategy,
|
|
184
186
|
evmAddress,
|
|
185
187
|
config.calldataAmountScale ?? 1n,
|
|
188
|
+
logger,
|
|
186
189
|
evmRpcUrl,
|
|
187
190
|
config.apiConfig.precompileAddress
|
|
188
191
|
)
|
|
@@ -207,7 +210,8 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
|
|
207
210
|
async function fetchTxDataFromRpc(
|
|
208
211
|
config: EvmConfigInfo,
|
|
209
212
|
currencyId: string,
|
|
210
|
-
txHash: string
|
|
213
|
+
txHash: string,
|
|
214
|
+
logger: Logger
|
|
211
215
|
): Promise<string | undefined> {
|
|
212
216
|
try {
|
|
213
217
|
const node = config.node
|
|
@@ -223,7 +227,7 @@ async function fetchTxDataFromRpc(
|
|
|
223
227
|
)
|
|
224
228
|
return data && data !== '0x' ? data : undefined
|
|
225
229
|
} catch (e) {
|
|
226
|
-
|
|
230
|
+
logger('coin-evm/staking', 'fetchTxDataFromRpc: getTransaction failed', {
|
|
227
231
|
currencyId,
|
|
228
232
|
txHash,
|
|
229
233
|
error: e instanceof Error ? e.message : String(e),
|
|
@@ -244,7 +248,8 @@ async function fetchTxDataFromRpc(
|
|
|
244
248
|
export async function resolveRedelegationValidators(
|
|
245
249
|
evmConfig: EvmConfigInfo,
|
|
246
250
|
currencyId: string,
|
|
247
|
-
operation: OperationLike
|
|
251
|
+
operation: OperationLike,
|
|
252
|
+
logger: Logger
|
|
248
253
|
): Promise<{
|
|
249
254
|
srcValidatorAddress: string
|
|
250
255
|
dstValidatorAddress: string
|
|
@@ -255,7 +260,7 @@ export async function resolveRedelegationValidators(
|
|
|
255
260
|
const payload =
|
|
256
261
|
typeof cached === 'string'
|
|
257
262
|
? cached
|
|
258
|
-
: await fetchTxDataFromRpc(evmConfig, currencyId, operation.hash)
|
|
263
|
+
: await fetchTxDataFromRpc(evmConfig, currencyId, operation.hash, logger)
|
|
259
264
|
|
|
260
265
|
if (!payload) return null
|
|
261
266
|
|
|
@@ -296,14 +301,15 @@ export async function resolveStakingValidator(
|
|
|
296
301
|
evmConfig: EvmConfigInfo,
|
|
297
302
|
currencyId: string,
|
|
298
303
|
operation: OperationLike,
|
|
299
|
-
operationType: 'delegate' | 'undelegate' | 'withdraw'
|
|
304
|
+
operationType: 'delegate' | 'undelegate' | 'withdraw',
|
|
305
|
+
logger: Logger
|
|
300
306
|
): Promise<{ validatorAddress: string; amount: BigNumber | null } | null> {
|
|
301
307
|
const extra = isRecord(operation.extra) ? operation.extra : undefined
|
|
302
308
|
const cached = extra?.contractPayload
|
|
303
309
|
const payload =
|
|
304
310
|
typeof cached === 'string'
|
|
305
311
|
? cached
|
|
306
|
-
: await fetchTxDataFromRpc(evmConfig, currencyId, operation.hash)
|
|
312
|
+
: await fetchTxDataFromRpc(evmConfig, currencyId, operation.hash, logger)
|
|
307
313
|
|
|
308
314
|
if (!payload) return null
|
|
309
315
|
|
|
@@ -318,7 +324,8 @@ export async function resolveStakingValidator(
|
|
|
318
324
|
const validatorAddress = await config.resolveValidatorAddress(
|
|
319
325
|
evmConfig,
|
|
320
326
|
d,
|
|
321
|
-
operation.recipients[0]
|
|
327
|
+
operation.recipients[0],
|
|
328
|
+
logger
|
|
322
329
|
)
|
|
323
330
|
if (!validatorAddress) return null
|
|
324
331
|
|
|
@@ -339,7 +346,8 @@ export async function resolveStakingValidator(
|
|
|
339
346
|
export async function buildRedelegationsFromOps(
|
|
340
347
|
evmConfig: EvmConfigInfo,
|
|
341
348
|
currencyId: string,
|
|
342
|
-
operations: OperationLike[]
|
|
349
|
+
operations: OperationLike[],
|
|
350
|
+
logger: Logger
|
|
343
351
|
): Promise<EvmRedelegation[]> {
|
|
344
352
|
const config = STAKING_CONTRACTS[currencyId]
|
|
345
353
|
if (!config?.functions.redelegate) return []
|
|
@@ -367,7 +375,7 @@ export async function buildRedelegationsFromOps(
|
|
|
367
375
|
const payload =
|
|
368
376
|
typeof cached === 'string'
|
|
369
377
|
? cached
|
|
370
|
-
: await fetchTxDataFromRpc(evmConfig, currencyId, op.hash)
|
|
378
|
+
: await fetchTxDataFromRpc(evmConfig, currencyId, op.hash, logger)
|
|
371
379
|
if (!payload) return null
|
|
372
380
|
try {
|
|
373
381
|
const d = iface.decodeFunctionData(functionName, payload)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { DeepPartialCtor } from '@ledgerhq/coin-module-framework/test/utils'
|
|
5
5
|
import { ethers } from 'ethers'
|
|
6
|
-
import { createMockEvmConfigInfo, mkExternalNode } from '../fixtures/context.fixtures'
|
|
6
|
+
import { createMockEvmConfigInfo, mkExternalNode, testLogger } from '../fixtures/context.fixtures'
|
|
7
7
|
import { fetchRewards } from './rewards'
|
|
8
8
|
import { USEI_TO_EVM_SCALE } from './utils'
|
|
9
9
|
|
|
@@ -74,7 +74,7 @@ describe('fetchRewards', () => {
|
|
|
74
74
|
},
|
|
75
75
|
])('returns an empty map when $case', async ({ currencyId, setup }) => {
|
|
76
76
|
setup()
|
|
77
|
-
expect(await fetchRewards(mockConfig, currencyId, EVM_ADDRESS)).toEqual(new Map())
|
|
77
|
+
expect(await fetchRewards(mockConfig, currencyId, EVM_ADDRESS, testLogger)).toEqual(new Map())
|
|
78
78
|
})
|
|
79
79
|
|
|
80
80
|
it('resolves the EVM address to its canonical Cosmos bech32 via the precompile', async () => {
|
|
@@ -82,7 +82,12 @@ describe('fetchRewards', () => {
|
|
|
82
82
|
mockGetSeiAddr.mockResolvedValueOnce(canonicalCosmosAddress)
|
|
83
83
|
mockNetwork.mockResolvedValueOnce(restResponse([]))
|
|
84
84
|
|
|
85
|
-
await fetchRewards(
|
|
85
|
+
await fetchRewards(
|
|
86
|
+
mockConfig,
|
|
87
|
+
'sei_evm',
|
|
88
|
+
'0x66c4371aE8FFeD2ec1c2EBbbcCfb7E494181E1E3',
|
|
89
|
+
testLogger
|
|
90
|
+
)
|
|
86
91
|
|
|
87
92
|
expect(mockNetwork.mock.calls[0][0]).toMatchObject({
|
|
88
93
|
url: expect.stringContaining(canonicalCosmosAddress),
|
|
@@ -100,7 +105,7 @@ describe('fetchRewards', () => {
|
|
|
100
105
|
])
|
|
101
106
|
)
|
|
102
107
|
|
|
103
|
-
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS)
|
|
108
|
+
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS, testLogger)
|
|
104
109
|
|
|
105
110
|
expect(result.size).toBe(1)
|
|
106
111
|
expect(result.get('seivaloper1one')).toBe(569n * USEI_TO_EVM_SCALE)
|
|
@@ -119,7 +124,7 @@ describe('fetchRewards', () => {
|
|
|
119
124
|
])
|
|
120
125
|
)
|
|
121
126
|
|
|
122
|
-
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS)
|
|
127
|
+
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS, testLogger)
|
|
123
128
|
|
|
124
129
|
expect(result.get('seivaloper1one')).toBe(123n * USEI_TO_EVM_SCALE)
|
|
125
130
|
})
|
|
@@ -137,7 +142,7 @@ describe('fetchRewards', () => {
|
|
|
137
142
|
])
|
|
138
143
|
)
|
|
139
144
|
|
|
140
|
-
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS)
|
|
145
|
+
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS, testLogger)
|
|
141
146
|
|
|
142
147
|
expect(result.get('seivaloper1one')).toBe(500n * USEI_TO_EVM_SCALE)
|
|
143
148
|
})
|
|
@@ -153,7 +158,7 @@ describe('fetchRewards', () => {
|
|
|
153
158
|
])
|
|
154
159
|
)
|
|
155
160
|
|
|
156
|
-
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS)
|
|
161
|
+
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS, testLogger)
|
|
157
162
|
|
|
158
163
|
expect(result.has('seivaloper1dust')).toBe(false)
|
|
159
164
|
expect(result.get('seivaloper1real')).toBe(42n * USEI_TO_EVM_SCALE)
|
|
@@ -168,7 +173,7 @@ describe('fetchRewards', () => {
|
|
|
168
173
|
])
|
|
169
174
|
)
|
|
170
175
|
|
|
171
|
-
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS)
|
|
176
|
+
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS, testLogger)
|
|
172
177
|
|
|
173
178
|
expect(result.size).toBe(3)
|
|
174
179
|
expect(result.get('seivaloper1a')).toBe(10n * USEI_TO_EVM_SCALE)
|
|
@@ -186,7 +191,7 @@ describe('fetchRewards', () => {
|
|
|
186
191
|
])
|
|
187
192
|
)
|
|
188
193
|
|
|
189
|
-
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS)
|
|
194
|
+
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS, testLogger)
|
|
190
195
|
|
|
191
196
|
expect(result.has('seivaloper1bad')).toBe(false)
|
|
192
197
|
})
|
|
@@ -204,7 +209,7 @@ describe('fetchRewards', () => {
|
|
|
204
209
|
])
|
|
205
210
|
)
|
|
206
211
|
|
|
207
|
-
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS)
|
|
212
|
+
const result = await fetchRewards(mockConfig, 'sei_evm', EVM_ADDRESS, testLogger)
|
|
208
213
|
|
|
209
214
|
expect(result.get('seivaloper1mixed')).toBe(100n * USEI_TO_EVM_SCALE)
|
|
210
215
|
})
|
package/src/staking/rewards.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import type { EvmConfigInfo } from '../config'
|
|
5
5
|
import type { RewardsStrategy } from '../types/staking'
|
|
6
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
6
7
|
import network from '@ledgerhq/live-network'
|
|
7
|
-
import { log } from '@ledgerhq/logs'
|
|
8
8
|
import { isExternalNodeConfig } from '../network/node/types'
|
|
9
9
|
import { STAKING_CONTRACTS } from './contracts'
|
|
10
10
|
import { getCosmosAddr } from './redelegations'
|
|
@@ -22,7 +22,8 @@ async function fetchCosmosRestRewards(
|
|
|
22
22
|
strategy: Extract<RewardsStrategy, { type: 'cosmos-rest' }>,
|
|
23
23
|
evmAddress: string,
|
|
24
24
|
evmRpcUrl: string,
|
|
25
|
-
precompileAddress: { address: string; abi: string }
|
|
25
|
+
precompileAddress: { address: string; abi: string },
|
|
26
|
+
logger: Logger
|
|
26
27
|
): Promise<Map<string, bigint>> {
|
|
27
28
|
const cosmosAddress = await getCosmosAddr(evmRpcUrl, precompileAddress, evmAddress)
|
|
28
29
|
if (!cosmosAddress) return new Map()
|
|
@@ -45,7 +46,7 @@ async function fetchCosmosRestRewards(
|
|
|
45
46
|
}
|
|
46
47
|
return result
|
|
47
48
|
} catch (e) {
|
|
48
|
-
|
|
49
|
+
logger('coin-evm/staking', 'fetchCosmosRestRewards: REST request or response parsing failed', {
|
|
49
50
|
url,
|
|
50
51
|
error: e instanceof Error ? e.message : String(e),
|
|
51
52
|
})
|
|
@@ -59,7 +60,8 @@ async function fetchCosmosRestRewards(
|
|
|
59
60
|
export async function fetchRewards(
|
|
60
61
|
evmConfig: EvmConfigInfo,
|
|
61
62
|
currencyId: string,
|
|
62
|
-
evmAddress: string
|
|
63
|
+
evmAddress: string,
|
|
64
|
+
logger: Logger
|
|
63
65
|
): Promise<Map<string, bigint>> {
|
|
64
66
|
try {
|
|
65
67
|
const config = STAKING_CONTRACTS[currencyId]
|
|
@@ -78,7 +80,8 @@ export async function fetchRewards(
|
|
|
78
80
|
strategy,
|
|
79
81
|
evmAddress,
|
|
80
82
|
evmRpcUrl,
|
|
81
|
-
apiConfig.precompileAddress
|
|
83
|
+
apiConfig.precompileAddress,
|
|
84
|
+
logger
|
|
82
85
|
)
|
|
83
86
|
}
|
|
84
87
|
default:
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { LogWithAddress } from '../network/node/types'
|
|
5
5
|
import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
|
|
6
|
+
import { testLogger } from '../fixtures/context.fixtures'
|
|
6
7
|
import { STAKING_CONTRACTS } from './contracts'
|
|
7
8
|
import { enrichRewardOperationsValue, sumRewardFromReceiptLogs } from './rewardsFromReceipt'
|
|
8
9
|
|
|
@@ -107,7 +108,7 @@ describe('enrichRewardOperationsValue', () => {
|
|
|
107
108
|
.fn()
|
|
108
109
|
.mockResolvedValue({ logs: [monadClaimRewardsLog(MONAD_DELEGATOR_TOPIC, '030405ea888e')] })
|
|
109
110
|
|
|
110
|
-
await enrichRewardOperationsValue('monad', [op], getReceipt)
|
|
111
|
+
await enrichRewardOperationsValue('monad', [op], getReceipt, testLogger)
|
|
111
112
|
|
|
112
113
|
expect(getReceipt).toHaveBeenCalledWith('0xabc')
|
|
113
114
|
expect(op.value).toStrictEqual(3315814008974n)
|
|
@@ -117,7 +118,7 @@ describe('enrichRewardOperationsValue', () => {
|
|
|
117
118
|
const op = rewardOp('0xabc', MONAD_DELEGATOR)
|
|
118
119
|
const getReceipt = jest.fn()
|
|
119
120
|
|
|
120
|
-
await enrichRewardOperationsValue('ethereum', [op], getReceipt)
|
|
121
|
+
await enrichRewardOperationsValue('ethereum', [op], getReceipt, testLogger)
|
|
121
122
|
|
|
122
123
|
expect(getReceipt).not.toHaveBeenCalled()
|
|
123
124
|
expect(op.value).toStrictEqual(0n)
|
|
@@ -134,7 +135,7 @@ describe('enrichRewardOperationsValue', () => {
|
|
|
134
135
|
}
|
|
135
136
|
const getReceipt = jest.fn().mockResolvedValue(null)
|
|
136
137
|
|
|
137
|
-
await enrichRewardOperationsValue('monad', [out, nonZero], getReceipt)
|
|
138
|
+
await enrichRewardOperationsValue('monad', [out, nonZero], getReceipt, testLogger)
|
|
138
139
|
|
|
139
140
|
expect(getReceipt).not.toHaveBeenCalled()
|
|
140
141
|
})
|
|
@@ -143,7 +144,7 @@ describe('enrichRewardOperationsValue', () => {
|
|
|
143
144
|
const op = rewardOp('0xabc', MONAD_DELEGATOR)
|
|
144
145
|
const getReceipt = jest.fn().mockRejectedValue(new Error('rpc down'))
|
|
145
146
|
|
|
146
|
-
await enrichRewardOperationsValue('monad', [op], getReceipt)
|
|
147
|
+
await enrichRewardOperationsValue('monad', [op], getReceipt, testLogger)
|
|
147
148
|
|
|
148
149
|
expect(op.value).toStrictEqual(0n)
|
|
149
150
|
})
|
|
@@ -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
|
})
|