@ledgerhq/coin-evm 5.3.1 → 5.3.3
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 +3 -13
- package/CHANGELOG.md +13 -0
- package/lib/adapters/blockOperations.d.ts +2 -2
- package/lib/adapters/blockOperations.d.ts.map +1 -1
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/logic/combine.d.ts +2 -1
- package/lib/logic/combine.d.ts.map +1 -1
- package/lib/logic/combine.js.map +1 -1
- package/lib/logic/common.d.ts +2 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransactionData.d.ts +1 -1
- package/lib/logic/craftTransactionData.d.ts.map +1 -1
- package/lib/logic/estimateFees.d.ts +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getStakes.d.ts +1 -1
- package/lib/logic/getStakes.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/validateIntent.d.ts +1 -1
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic.d.ts +1 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +4 -4
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/index.d.ts +2 -2
- package/lib/network/explorer/index.d.ts.map +1 -1
- package/lib/network/explorer/index.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts +2 -2
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/none.d.ts +1 -1
- package/lib/network/explorer/none.d.ts.map +1 -1
- package/lib/network/explorer/none.js.map +1 -1
- package/lib/network/explorer/types.d.ts +1 -1
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/gasTracker/index.d.ts +2 -2
- package/lib/network/gasTracker/index.d.ts.map +1 -1
- package/lib/network/gasTracker/index.js.map +1 -1
- package/lib/network/gasTracker/ledger.d.ts +3 -3
- package/lib/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib/network/gasTracker/ledger.js.map +1 -1
- package/lib/network/gasTracker/types.d.ts +2 -2
- package/lib/network/gasTracker/types.d.ts.map +1 -1
- package/lib/network/node/ledger.d.ts +2 -2
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +3 -3
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/staking/validators/monad.d.ts +2 -1
- package/lib/staking/validators/monad.d.ts.map +1 -1
- 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.map +1 -1
- package/lib/staking/validators/somnia.d.ts.map +1 -1
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib/types/assets.d.ts +1 -1
- package/lib/types/assets.d.ts.map +1 -1
- package/lib/types/transaction.d.ts +1 -1
- package/lib/types/transaction.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.d.ts +2 -2
- package/lib-es/adapters/blockOperations.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/api/index.d.ts +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/config.d.ts +1 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/logic/combine.d.ts +2 -1
- package/lib-es/logic/combine.d.ts.map +1 -1
- package/lib-es/logic/combine.js.map +1 -1
- package/lib-es/logic/common.d.ts +2 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +1 -1
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransactionData.d.ts +1 -1
- package/lib-es/logic/craftTransactionData.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getStakes.d.ts +1 -1
- package/lib-es/logic/getStakes.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts +1 -1
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic.d.ts +1 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +4 -4
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/index.d.ts +2 -2
- package/lib-es/network/explorer/index.d.ts.map +1 -1
- package/lib-es/network/explorer/index.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts +2 -2
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/none.d.ts +1 -1
- package/lib-es/network/explorer/none.d.ts.map +1 -1
- package/lib-es/network/explorer/none.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +1 -1
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.d.ts +2 -2
- package/lib-es/network/gasTracker/index.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.js.map +1 -1
- package/lib-es/network/gasTracker/ledger.d.ts +3 -3
- package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib-es/network/gasTracker/ledger.js +1 -1
- package/lib-es/network/gasTracker/ledger.js.map +1 -1
- package/lib-es/network/gasTracker/types.d.ts +2 -2
- package/lib-es/network/gasTracker/types.d.ts.map +1 -1
- package/lib-es/network/node/ledger.d.ts +2 -2
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +1 -1
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +3 -3
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.d.ts +2 -1
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- 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.map +1 -1
- package/lib-es/staking/validators/somnia.d.ts.map +1 -1
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/types/assets.d.ts +1 -1
- package/lib-es/types/assets.d.ts.map +1 -1
- package/lib-es/types/transaction.d.ts +1 -1
- package/lib-es/types/transaction.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/adapters/blockOperations.test.ts +29 -31
- package/src/adapters/blockOperations.ts +3 -2
- package/src/adapters/etherscan.test.ts +7 -7
- package/src/adapters/ledger.test.ts +2 -2
- package/src/api/getBlock.integ.test.ts +1 -1
- package/src/api/index.fantom.integ.test.ts +1 -1
- package/src/api/index.flare.integ.test.ts +2 -14
- package/src/api/index.integ.test.ts +330 -246
- package/src/api/index.linea.integ.test.ts +1 -1
- package/src/api/index.optimism.integ.test.ts +1 -1
- package/src/api/index.shape.integ.test.ts +1 -1
- package/src/api/index.ts +1 -1
- package/src/config.ts +1 -1
- package/src/fixtures/context.fixtures.ts +79 -1
- package/src/fixtures/ethers.fixtures.ts +26 -0
- package/src/fixtures/ledger.fixtures.ts +1 -1
- package/src/internalTxSources.test.ts +3 -6
- package/src/logic/broadcast.integ.test.ts +6 -18
- package/src/logic/broadcast.test.ts +19 -31
- package/src/logic/broadcastSource.test.ts +6 -7
- package/src/logic/combine.test.ts +2 -2
- package/src/logic/combine.ts +2 -1
- package/src/logic/common.test.ts +120 -112
- package/src/logic/common.ts +2 -7
- package/src/logic/craftTransaction.test.ts +163 -200
- package/src/logic/craftTransaction.ts +3 -2
- package/src/logic/craftTransactionData.test.ts +6 -6
- package/src/logic/craftTransactionData.ts +1 -1
- package/src/logic/estimateFees.test.ts +19 -15
- package/src/logic/estimateFees.ts +6 -3
- package/src/logic/getBalance.test.ts +16 -15
- package/src/logic/getBalance.ts +4 -3
- package/src/logic/getBlock.test.ts +379 -388
- package/src/logic/getBlock.ts +3 -2
- package/src/logic/getBlockInfo.test.ts +7 -9
- package/src/logic/getNextSequence.test.ts +5 -5
- package/src/logic/getStakes.test.ts +35 -35
- package/src/logic/getStakes.ts +1 -1
- package/src/logic/internalTransactionsFetcher.test.ts +26 -24
- package/src/logic/internalTransactionsFetcher.ts +1 -1
- package/src/logic/lastBlock.test.ts +29 -20
- package/src/logic/listOperations.test.ts +44 -40
- package/src/logic/validateIntent.test.ts +152 -101
- package/src/logic/validateIntent.ts +4 -2
- package/src/logic.test.ts +13 -18
- package/src/logic.ts +1 -1
- package/src/network/explorer/etherscan.test.ts +6 -6
- package/src/network/explorer/etherscan.ts +12 -10
- package/src/network/explorer/index.test.ts +52 -22
- package/src/network/explorer/index.ts +2 -2
- package/src/network/explorer/ledger.test.ts +17 -5
- package/src/network/explorer/ledger.ts +3 -2
- package/src/network/explorer/none.ts +2 -1
- package/src/network/explorer/types.ts +1 -1
- package/src/network/gasTracker/index.test.ts +14 -8
- package/src/network/gasTracker/index.ts +2 -2
- package/src/network/gasTracker/ledger.test.ts +34 -29
- package/src/network/gasTracker/ledger.ts +5 -7
- package/src/network/gasTracker/types.ts +2 -2
- package/src/network/node/index.memoization.test.ts +25 -31
- package/src/network/node/index.test.ts +14 -25
- package/src/network/node/ledger.test.ts +45 -60
- package/src/network/node/ledger.ts +6 -5
- package/src/network/node/node.fixtures.ts +0 -2
- package/src/network/node/rpc.common.ts +14 -14
- package/src/network/node/rpc.test.ts +153 -184
- package/src/network/node/types.ts +3 -3
- package/src/staking/detectOperationType.test.ts +1 -1
- package/src/staking/encoder.test.ts +14 -22
- package/src/staking/logic.test.ts +20 -14
- package/src/staking/operations/index.test.ts +29 -29
- package/src/staking/prepareIntents.test.ts +26 -20
- package/src/staking/redelegations.test.ts +50 -33
- package/src/staking/rewards.test.ts +29 -17
- package/src/staking/rewardsFromReceipt.test.ts +20 -21
- package/src/staking/transactionData.test.ts +23 -23
- package/src/staking/validators/monad.test.ts +65 -24
- package/src/staking/validators/monad.ts +2 -1
- package/src/staking/validators/monadResolver.ts +2 -1
- package/src/staking/validators/somnia.test.ts +21 -13
- package/src/staking/validators/somnia.ts +2 -1
- package/src/staking/validators/zero_gravity.test.ts +118 -48
- package/src/staking/validators/zero_gravity.ts +2 -1
- package/src/staking/validators.integ.test.ts +13 -25
- package/src/staking/validators.test.ts +7 -2
- package/src/types/assets.ts +1 -1
- package/src/types/transaction.ts +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { LogWithAddress } from '../network/node/types'
|
|
4
5
|
import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
|
|
5
|
-
import { LogWithAddress } from '../network/node/types'
|
|
6
6
|
import { STAKING_CONTRACTS } from './contracts'
|
|
7
7
|
import { enrichRewardOperationsValue, sumRewardFromReceiptLogs } from './rewardsFromReceipt'
|
|
8
8
|
|
|
@@ -85,22 +85,21 @@ describe('sumRewardFromReceiptLogs', () => {
|
|
|
85
85
|
})
|
|
86
86
|
|
|
87
87
|
describe('enrichRewardOperationsValue', () => {
|
|
88
|
-
const rewardOp = (hash: string, sender: string): Operation<MemoNotSupported> =>
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}) as Operation<MemoNotSupported>
|
|
88
|
+
const rewardOp = (hash: string, sender: string): Operation<MemoNotSupported> => ({
|
|
89
|
+
id: `${sender}-${hash}-REWARD`,
|
|
90
|
+
type: 'REWARD',
|
|
91
|
+
value: 0n,
|
|
92
|
+
senders: [sender],
|
|
93
|
+
recipients: [MONAD_STAKING],
|
|
94
|
+
asset: { type: 'native' as const },
|
|
95
|
+
tx: {
|
|
96
|
+
hash,
|
|
97
|
+
block: { height: 0, hash: '0x', time: new Date() },
|
|
98
|
+
fees: 0n,
|
|
99
|
+
date: new Date(),
|
|
100
|
+
failed: false,
|
|
101
|
+
},
|
|
102
|
+
})
|
|
104
103
|
|
|
105
104
|
it('patches the REWARD op value from the receipt logs', async () => {
|
|
106
105
|
const op = rewardOp('0xabc', MONAD_DELEGATOR)
|
|
@@ -125,14 +124,14 @@ describe('enrichRewardOperationsValue', () => {
|
|
|
125
124
|
})
|
|
126
125
|
|
|
127
126
|
it('only fetches receipts for zero-value REWARD ops', async () => {
|
|
128
|
-
const out = {
|
|
127
|
+
const out: Operation<MemoNotSupported> = {
|
|
129
128
|
...rewardOp('0xout', MONAD_DELEGATOR),
|
|
130
129
|
type: 'OUT',
|
|
131
|
-
}
|
|
132
|
-
const nonZero = {
|
|
130
|
+
}
|
|
131
|
+
const nonZero: Operation<MemoNotSupported> = {
|
|
133
132
|
...rewardOp('0xnz', MONAD_DELEGATOR),
|
|
134
133
|
value: 5n,
|
|
135
|
-
}
|
|
134
|
+
}
|
|
136
135
|
const getReceipt = jest.fn().mockResolvedValue(null)
|
|
137
136
|
|
|
138
137
|
await enrichRewardOperationsValue('monad', [out, nonZero], getReceipt)
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { MemoNotSupported } from '@ledgerhq/coin-module-framework/api/index'
|
|
5
|
-
import {
|
|
4
|
+
import type { MemoNotSupported } from '@ledgerhq/coin-module-framework/api/index'
|
|
5
|
+
import type { BufferTxData } from '@ledgerhq/coin-module-framework/api/types'
|
|
6
|
+
import { createStakingTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
|
|
6
7
|
import { ethers } from 'ethers'
|
|
7
8
|
import { getStakingABI } from './abis'
|
|
8
9
|
import { STAKING_CONTRACTS } from './contracts'
|
|
9
10
|
import { buildStakingTransactionParams } from './transactionData'
|
|
10
11
|
|
|
11
|
-
const delegateIntent = (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}) as unknown as TransactionIntent<MemoNotSupported, BufferTxData>
|
|
12
|
+
const delegateIntent = (fields: Record<string, unknown>) =>
|
|
13
|
+
Object.assign(
|
|
14
|
+
createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
15
|
+
type: 'staking-legacy',
|
|
16
|
+
mode: 'delegate',
|
|
17
|
+
amount: 1000000000000000000n,
|
|
18
|
+
asset: { type: 'native' },
|
|
19
|
+
recipient: '0xRecipient',
|
|
20
|
+
sender: '0xSender',
|
|
21
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
22
|
+
}),
|
|
23
|
+
fields
|
|
24
|
+
)
|
|
25
25
|
|
|
26
26
|
describe('buildStakingTransactionParams', () => {
|
|
27
27
|
it('encodes a Monad delegate by valId with the amount carried as msg.value', () => {
|
|
@@ -32,7 +32,7 @@ describe('buildStakingTransactionParams', () => {
|
|
|
32
32
|
|
|
33
33
|
const { to, data, value } = buildStakingTransactionParams('monad', intent)
|
|
34
34
|
|
|
35
|
-
const iface = new ethers.Interface(getStakingABI('monad')
|
|
35
|
+
const iface = new ethers.Interface(getStakingABI('monad') ?? [])
|
|
36
36
|
expect('0x' + data.toString('hex')).toEqual(iface.encodeFunctionData('delegate', [42n]))
|
|
37
37
|
expect(to).toEqual('0x0000000000000000000000000000000000001000')
|
|
38
38
|
expect(value).toEqual(1000000000000000000n)
|
|
@@ -48,7 +48,7 @@ describe('buildStakingTransactionParams', () => {
|
|
|
48
48
|
|
|
49
49
|
const { to, data, value } = buildStakingTransactionParams('monad', intent)
|
|
50
50
|
|
|
51
|
-
const iface = new ethers.Interface(getStakingABI('monad')
|
|
51
|
+
const iface = new ethers.Interface(getStakingABI('monad') ?? [])
|
|
52
52
|
expect('0x' + data.toString('hex')).toEqual(iface.encodeFunctionData('compound', [42n]))
|
|
53
53
|
expect(to).toEqual('0x0000000000000000000000000000000000001000')
|
|
54
54
|
expect(value).toEqual(0n)
|
|
@@ -70,7 +70,7 @@ describe('buildStakingTransactionParams', () => {
|
|
|
70
70
|
|
|
71
71
|
const { to, data, value } = buildStakingTransactionParams('monad', intent)
|
|
72
72
|
|
|
73
|
-
const iface = new ethers.Interface(getStakingABI('monad')
|
|
73
|
+
const iface = new ethers.Interface(getStakingABI('monad') ?? [])
|
|
74
74
|
expect('0x' + data.toString('hex')).toEqual(iface.encodeFunctionData('withdraw', [42n, 7n]))
|
|
75
75
|
expect(to).toEqual('0x0000000000000000000000000000000000001000')
|
|
76
76
|
expect(value).toEqual(0n)
|
|
@@ -88,7 +88,7 @@ describe('buildStakingTransactionParams', () => {
|
|
|
88
88
|
|
|
89
89
|
const { to, data, value } = buildStakingTransactionParams('sei_evm', intent)
|
|
90
90
|
|
|
91
|
-
const iface = new ethers.Interface(getStakingABI('sei_evm')
|
|
91
|
+
const iface = new ethers.Interface(getStakingABI('sei_evm') ?? [])
|
|
92
92
|
expect('0x' + data.toString('hex')).toEqual(iface.encodeFunctionData('delegate', [valAddress]))
|
|
93
93
|
expect(to).toEqual('0x0000000000000000000000000000000000001005')
|
|
94
94
|
expect(value).toEqual(1000000000000000000n)
|
|
@@ -124,7 +124,7 @@ describe('0G / zero_gravity delegate', () => {
|
|
|
124
124
|
|
|
125
125
|
const { to, data, value } = buildStakingTransactionParams('zero_gravity', intent)
|
|
126
126
|
|
|
127
|
-
const iface = new ethers.Interface(getStakingABI('zero_gravity')
|
|
127
|
+
const iface = new ethers.Interface(getStakingABI('zero_gravity') ?? [])
|
|
128
128
|
expect('0x' + data.toString('hex')).toEqual(
|
|
129
129
|
iface.encodeFunctionData('delegate', ['0x0000000000000000000000000000000000000002'])
|
|
130
130
|
)
|
|
@@ -134,7 +134,7 @@ describe('0G / zero_gravity delegate', () => {
|
|
|
134
134
|
|
|
135
135
|
it('throws when valAddress is missing', () => {
|
|
136
136
|
expect(() => {
|
|
137
|
-
buildStakingTransactionParams('zero_gravity', delegateIntent({}))
|
|
137
|
+
buildStakingTransactionParams('zero_gravity', delegateIntent({ valAddress: '' }))
|
|
138
138
|
}).toThrow('0G staking requires a validator address')
|
|
139
139
|
})
|
|
140
140
|
|
|
@@ -164,7 +164,7 @@ describe('0G / zero_gravity undelegate', () => {
|
|
|
164
164
|
|
|
165
165
|
const { to, data, value } = buildStakingTransactionParams('zero_gravity', intent)
|
|
166
166
|
|
|
167
|
-
const iface = new ethers.Interface(getStakingABI('zero_gravity')
|
|
167
|
+
const iface = new ethers.Interface(getStakingABI('zero_gravity') ?? [])
|
|
168
168
|
expect('0x' + data.toString('hex')).toEqual(
|
|
169
169
|
iface.encodeFunctionData('undelegate', [DELEGATOR, 1_500_000_000n])
|
|
170
170
|
)
|
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { EvmConfigInfo } from '../../config'
|
|
5
|
+
import type { StakingContractConfig } from '../../types/staking'
|
|
6
|
+
import type { AddressLike } from 'ethers'
|
|
5
7
|
import network from '@ledgerhq/live-network'
|
|
6
8
|
import { ethers } from 'ethers'
|
|
7
9
|
import monadAbi from '../../abis/monad.abi.json'
|
|
10
|
+
import {
|
|
11
|
+
createMockEvmConfigInfo,
|
|
12
|
+
mkExternalNode,
|
|
13
|
+
mkLedgerNode,
|
|
14
|
+
} from '../../fixtures/context.fixtures'
|
|
15
|
+
import { mkJsonRpcProvider } from '../../fixtures/ethers.fixtures'
|
|
8
16
|
import { withApi } from '../../network/node/rpc.common'
|
|
9
17
|
import { fetchMonadStakes, extractMonadKnownValIds } from './monad'
|
|
10
18
|
import { getValidatorAddressById } from './monadResolver'
|
|
@@ -22,11 +30,12 @@ jest.mock('@ledgerhq/live-network', () => ({
|
|
|
22
30
|
const mockedWithApi = jest.mocked(withApi)
|
|
23
31
|
const mockedNetwork = jest.mocked(network)
|
|
24
32
|
|
|
25
|
-
const mockConfig = {
|
|
33
|
+
const mockConfig = createMockEvmConfigInfo({
|
|
34
|
+
chainId: 10143,
|
|
26
35
|
name: 'Monad',
|
|
27
|
-
node: {
|
|
28
|
-
}
|
|
29
|
-
const ledgerConfig = {
|
|
36
|
+
node: mkExternalNode({ uri: 'https://monad.rpc/' }),
|
|
37
|
+
})
|
|
38
|
+
const ledgerConfig = createMockEvmConfigInfo({ chainId: 10143, node: mkLedgerNode() })
|
|
30
39
|
|
|
31
40
|
const monadIface = new ethers.Interface(monadAbi)
|
|
32
41
|
const PRECOMPILE = '0x0000000000000000000000000000000000001000'
|
|
@@ -54,13 +63,18 @@ const encodeGetValidator = (params: {
|
|
|
54
63
|
'0x',
|
|
55
64
|
])
|
|
56
65
|
|
|
57
|
-
type CallHandler = (request: {
|
|
66
|
+
type CallHandler = (request: {
|
|
67
|
+
to?: AddressLike | null
|
|
68
|
+
data?: string | Uint8Array | null
|
|
69
|
+
}) => Promise<string>
|
|
58
70
|
|
|
59
71
|
const setupRpc = (handler: CallHandler) => {
|
|
60
72
|
const callMock = jest.fn(handler)
|
|
61
|
-
mockedWithApi.mockImplementation(async (_config, _currencyId, fn) =>
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
mockedWithApi.mockImplementation(async (_config, _currencyId, fn) => {
|
|
74
|
+
const api = mkJsonRpcProvider()
|
|
75
|
+
jest.spyOn(api, 'call').mockImplementation(callMock)
|
|
76
|
+
return fn(api)
|
|
77
|
+
})
|
|
64
78
|
return callMock
|
|
65
79
|
}
|
|
66
80
|
|
|
@@ -81,36 +95,36 @@ const routeByName = (responses: {
|
|
|
81
95
|
const desc = monadIface.parseTransaction({ data })
|
|
82
96
|
if (!desc) throw new Error('could not parse calldata')
|
|
83
97
|
if (desc.name === 'getExecutionValidatorSet') {
|
|
84
|
-
const startIndex = desc.args[0]
|
|
98
|
+
const startIndex: bigint = desc.args[0]
|
|
85
99
|
const out = responses.getExecutionValidatorSet?.(startIndex)
|
|
86
100
|
if (out instanceof Error) throw out
|
|
87
101
|
if (!out) throw new Error(`no response for getExecutionValidatorSet(${startIndex})`)
|
|
88
102
|
return out
|
|
89
103
|
}
|
|
90
104
|
if (desc.name === 'getValidator') {
|
|
91
|
-
const valId = desc.args[0]
|
|
105
|
+
const valId: bigint = desc.args[0]
|
|
92
106
|
const out = responses.getValidator?.(valId)
|
|
93
107
|
if (out instanceof Error) throw out
|
|
94
108
|
if (!out) throw new Error(`no response for getValidator(${valId})`)
|
|
95
109
|
return out
|
|
96
110
|
}
|
|
97
111
|
if (desc.name === 'getDelegations') {
|
|
98
|
-
const startValId = desc.args[1]
|
|
112
|
+
const startValId: bigint = desc.args[1]
|
|
99
113
|
const out = responses.getDelegations?.(startValId)
|
|
100
114
|
if (out instanceof Error) throw out
|
|
101
115
|
if (!out) throw new Error(`no response for getDelegations(${startValId})`)
|
|
102
116
|
return out
|
|
103
117
|
}
|
|
104
118
|
if (desc.name === 'getDelegator') {
|
|
105
|
-
const valId = desc.args[0]
|
|
119
|
+
const valId: bigint = desc.args[0]
|
|
106
120
|
const out = responses.getDelegator?.(valId)
|
|
107
121
|
if (out instanceof Error) throw out
|
|
108
122
|
if (!out) throw new Error(`no response for getDelegator(${valId})`)
|
|
109
123
|
return out
|
|
110
124
|
}
|
|
111
125
|
if (desc.name === 'getWithdrawalRequest') {
|
|
112
|
-
const valId = desc.args[0]
|
|
113
|
-
const withdrawId = Number(desc.args[2]
|
|
126
|
+
const valId: bigint = desc.args[0]
|
|
127
|
+
const withdrawId = Number(desc.args[2])
|
|
114
128
|
// Default unhandled slots to "free" (all-zero) so tests that don't care about
|
|
115
129
|
// withdrawals aren't forced to stub all 256 slots.
|
|
116
130
|
const out =
|
|
@@ -204,7 +218,8 @@ describe('staking/validators/monad', () => {
|
|
|
204
218
|
// Repo filename is the lowercase secp hex without the `0x` prefix.
|
|
205
219
|
mockedNetwork.mockResolvedValueOnce({
|
|
206
220
|
data: { name: 'GalaxyDigital' },
|
|
207
|
-
|
|
221
|
+
status: 200,
|
|
222
|
+
})
|
|
208
223
|
|
|
209
224
|
const page = await getValidators(mockConfig, 'monad')
|
|
210
225
|
|
|
@@ -441,9 +456,16 @@ describe('staking/validators/monad', () => {
|
|
|
441
456
|
describe('fetchMonadStakes', () => {
|
|
442
457
|
const DELEGATOR = '0x00000000000000000000000000000000000000aa'
|
|
443
458
|
const SECP = '0x036e44a092493800e427b2b08d3427d804348b1368ecd0a6af6510ae40ce507187'
|
|
459
|
+
const dummyStakingConfig: StakingContractConfig = {
|
|
460
|
+
contractAddress: () => '',
|
|
461
|
+
value: () => 0n,
|
|
462
|
+
functions: { delegate: '', undelegate: '', getStakedBalance: '' },
|
|
463
|
+
resolveValidatorAddress: async () => null,
|
|
464
|
+
resolveOperationAmount: async () => null,
|
|
465
|
+
}
|
|
444
466
|
|
|
445
467
|
const fetchStakes = (config: EvmConfigInfo = mockConfig) =>
|
|
446
|
-
fetchMonadStakes(config, DELEGATOR,
|
|
468
|
+
fetchMonadStakes(config, DELEGATOR, dummyStakingConfig, 'monad')
|
|
447
469
|
|
|
448
470
|
const encodeDelegator = (
|
|
449
471
|
stake: bigint,
|
|
@@ -516,7 +538,8 @@ describe('staking/validators/monad', () => {
|
|
|
516
538
|
)
|
|
517
539
|
mockedNetwork.mockResolvedValueOnce({
|
|
518
540
|
data: { name: 'GalaxyDigital' },
|
|
519
|
-
|
|
541
|
+
status: 200,
|
|
542
|
+
})
|
|
520
543
|
|
|
521
544
|
const stakes = await fetchStakes()
|
|
522
545
|
|
|
@@ -832,7 +855,9 @@ describe('staking/validators/monad', () => {
|
|
|
832
855
|
})
|
|
833
856
|
)
|
|
834
857
|
|
|
835
|
-
const stakes = await fetchMonadStakes(mockConfig, DELEGATOR,
|
|
858
|
+
const stakes = await fetchMonadStakes(mockConfig, DELEGATOR, dummyStakingConfig, 'monad', [
|
|
859
|
+
'92',
|
|
860
|
+
])
|
|
836
861
|
|
|
837
862
|
const withdrawal = stakes.find((s) => s.details?.validatorId === '92')
|
|
838
863
|
expect(withdrawal).toMatchObject({
|
|
@@ -855,7 +880,9 @@ describe('staking/validators/monad', () => {
|
|
|
855
880
|
})
|
|
856
881
|
)
|
|
857
882
|
|
|
858
|
-
const stakes = await fetchMonadStakes(mockConfig, DELEGATOR,
|
|
883
|
+
const stakes = await fetchMonadStakes(mockConfig, DELEGATOR, dummyStakingConfig, 'monad', [
|
|
884
|
+
'7',
|
|
885
|
+
])
|
|
859
886
|
|
|
860
887
|
expect(stakes).toHaveLength(1)
|
|
861
888
|
expect(delegatorCallCount).toBe(1)
|
|
@@ -863,11 +890,25 @@ describe('staking/validators/monad', () => {
|
|
|
863
890
|
})
|
|
864
891
|
|
|
865
892
|
describe('extractMonadKnownValIds', () => {
|
|
866
|
-
const makeOp = (
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
893
|
+
const makeOp = (
|
|
894
|
+
type: string,
|
|
895
|
+
contractPayload?: string
|
|
896
|
+
): Parameters<typeof extractMonadKnownValIds>[1][number] => ({
|
|
897
|
+
id: '',
|
|
898
|
+
type,
|
|
899
|
+
senders: [],
|
|
900
|
+
recipients: [],
|
|
901
|
+
value: 0n,
|
|
902
|
+
asset: { type: 'native' },
|
|
903
|
+
...(contractPayload !== undefined ? { details: { contractPayload } } : {}),
|
|
904
|
+
tx: {
|
|
905
|
+
hash: '',
|
|
906
|
+
block: { height: 0, hash: '', time: new Date(0) },
|
|
907
|
+
fees: 0n,
|
|
908
|
+
date: new Date(0),
|
|
909
|
+
failed: false,
|
|
910
|
+
},
|
|
911
|
+
})
|
|
871
912
|
|
|
872
913
|
it('extracts a validator id from a DELEGATE op', () => {
|
|
873
914
|
const payload = monadIface.encodeFunctionData('delegate', [42n])
|
|
@@ -13,10 +13,11 @@ import type {
|
|
|
13
13
|
StakeState,
|
|
14
14
|
Validator,
|
|
15
15
|
} from '@ledgerhq/coin-module-framework/api/types'
|
|
16
|
+
import type { JsonRpcProvider } from 'ethers'
|
|
16
17
|
import network from '@ledgerhq/live-network'
|
|
17
18
|
import { makeLRUCache } from '@ledgerhq/live-network/cache'
|
|
18
19
|
import { log } from '@ledgerhq/logs'
|
|
19
|
-
import { ethers
|
|
20
|
+
import { ethers } from 'ethers'
|
|
20
21
|
import { evmUnit } from '../../logic/evmUnit'
|
|
21
22
|
import { withApi } from '../../network/node/rpc.common'
|
|
22
23
|
import { isExternalNodeConfig } from '../../network/node/types'
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { EvmConfigInfo } from '../../config'
|
|
5
|
+
import type { JsonRpcProvider } from 'ethers'
|
|
5
6
|
import { log } from '@ledgerhq/logs'
|
|
6
|
-
import { ethers
|
|
7
|
+
import { ethers } from 'ethers'
|
|
7
8
|
import { withApi } from '../../network/node/rpc.common'
|
|
8
9
|
import { isExternalNodeConfig } from '../../network/node/types'
|
|
9
10
|
import { getStakingABI } from '../abis'
|
|
@@ -2,10 +2,18 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { EvmConfigInfo } from '../../config'
|
|
5
|
+
import type { DeepPartialReturn } from '@ledgerhq/coin-module-framework/test/utils'
|
|
6
|
+
import type { TransactionRequest } from 'ethers'
|
|
5
7
|
import network from '@ledgerhq/live-network'
|
|
6
8
|
import { ethers } from 'ethers'
|
|
7
9
|
import somniaAbi from '../../abis/somnia.abi.json'
|
|
10
|
+
import {
|
|
11
|
+
createMockEvmConfigInfo,
|
|
12
|
+
mkExternalNode,
|
|
13
|
+
mkLedgerNode,
|
|
14
|
+
} from '../../fixtures/context.fixtures'
|
|
8
15
|
import { withApi } from '../../network/node/rpc.common'
|
|
16
|
+
import { STAKING_CONTRACTS } from '../contracts'
|
|
9
17
|
import { clearValidatorNamesCache, fetchSomniaStakes, fetchValidatorNames } from './somnia'
|
|
10
18
|
import { clearValidatorsCache, getValidators } from './index'
|
|
11
19
|
|
|
@@ -13,13 +21,14 @@ jest.mock('../../network/node/rpc.common', () => ({ __esModule: true, withApi: j
|
|
|
13
21
|
jest.mock('@ledgerhq/live-network', () => ({ __esModule: true, default: jest.fn() }))
|
|
14
22
|
|
|
15
23
|
const mockedWithApi = jest.mocked(withApi)
|
|
16
|
-
const mockedNetwork = jest.mocked(network)
|
|
24
|
+
const mockedNetwork = jest.mocked<DeepPartialReturn<typeof network>>(network)
|
|
17
25
|
|
|
18
|
-
const mockConfig = {
|
|
26
|
+
const mockConfig = createMockEvmConfigInfo({
|
|
27
|
+
chainId: 5031,
|
|
28
|
+
node: mkExternalNode({ uri: 'https://somnia-rpc.publicnode.com' }),
|
|
19
29
|
name: 'Somnia',
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const ledgerConfig = { node: { type: 'ledger' } } as unknown as EvmConfigInfo
|
|
30
|
+
})
|
|
31
|
+
const ledgerConfig = createMockEvmConfigInfo({ chainId: 5031, node: mkLedgerNode() })
|
|
23
32
|
|
|
24
33
|
const somniaIface = new ethers.Interface(somniaAbi)
|
|
25
34
|
const CONTRACT = '0xBe367d410D96E1cAeF68C0632251072CDf1b8250'
|
|
@@ -27,12 +36,12 @@ const VALIDATOR_A = ethers.getAddress('0x' + 'aa'.repeat(20))
|
|
|
27
36
|
const VALIDATOR_B = ethers.getAddress('0x' + 'bb'.repeat(20))
|
|
28
37
|
const DELEGATOR = ethers.getAddress('0x' + 'cc'.repeat(20))
|
|
29
38
|
|
|
30
|
-
type CallHandler = (request:
|
|
39
|
+
type CallHandler = (request: TransactionRequest) => Promise<string>
|
|
31
40
|
|
|
32
41
|
const setupRpc = (handler: CallHandler) => {
|
|
33
42
|
const callMock = jest.fn(handler)
|
|
34
43
|
mockedWithApi.mockImplementation(async (_config, _currencyId, fn) =>
|
|
35
|
-
fn({ call: callMock }
|
|
44
|
+
fn(Object.assign(Object.create(null), { call: callMock }))
|
|
36
45
|
)
|
|
37
46
|
return callMock
|
|
38
47
|
}
|
|
@@ -83,7 +92,7 @@ const routeByName = (responses: {
|
|
|
83
92
|
return out
|
|
84
93
|
}
|
|
85
94
|
if (desc.name === 'getStake') {
|
|
86
|
-
const address = desc.args[0]
|
|
95
|
+
const address = desc.args[0]
|
|
87
96
|
const out = responses.getStake?.(address)
|
|
88
97
|
if (out instanceof Error) throw out
|
|
89
98
|
if (!out) throw new Error(`no response for getStake(${address})`)
|
|
@@ -96,7 +105,7 @@ const routeByName = (responses: {
|
|
|
96
105
|
return out
|
|
97
106
|
}
|
|
98
107
|
if (desc.name === 'getDelegationInfo') {
|
|
99
|
-
const validator = desc.args[1]
|
|
108
|
+
const validator = desc.args[1]
|
|
100
109
|
const out = responses.getDelegationInfo?.(validator)
|
|
101
110
|
if (out instanceof Error) throw out
|
|
102
111
|
if (!out) throw new Error(`no response for getDelegationInfo(${validator})`)
|
|
@@ -197,8 +206,7 @@ describe('staking/validators/somnia', () => {
|
|
|
197
206
|
})
|
|
198
207
|
|
|
199
208
|
describe('fetchValidatorNames', () => {
|
|
200
|
-
const mockNamesResponse = (data: unknown) =>
|
|
201
|
-
mockedNetwork.mockResolvedValue({ data } as unknown as Awaited<ReturnType<typeof network>>)
|
|
209
|
+
const mockNamesResponse = (data: unknown) => mockedNetwork.mockResolvedValue({ data })
|
|
202
210
|
|
|
203
211
|
it('returns a lowercased address -> name map from a valid flat map', async () => {
|
|
204
212
|
mockNamesResponse({
|
|
@@ -277,7 +285,7 @@ describe('staking/validators/somnia', () => {
|
|
|
277
285
|
|
|
278
286
|
describe('fetchSomniaStakes', () => {
|
|
279
287
|
const fetchStakes = (config: EvmConfigInfo = mockConfig) =>
|
|
280
|
-
fetchSomniaStakes(config, DELEGATOR,
|
|
288
|
+
fetchSomniaStakes(config, DELEGATOR, STAKING_CONTRACTS['somnia'], 'somnia')
|
|
281
289
|
|
|
282
290
|
const defaultStakeHandlers = (
|
|
283
291
|
overrides: {
|
|
@@ -351,7 +359,7 @@ describe('staking/validators/somnia', () => {
|
|
|
351
359
|
it('attaches the validator name from the names overlay to details.validatorName', async () => {
|
|
352
360
|
mockedNetwork.mockResolvedValue({
|
|
353
361
|
data: { [VALIDATOR_A.toLowerCase()]: 'Everstake' },
|
|
354
|
-
}
|
|
362
|
+
})
|
|
355
363
|
setupRpc(defaultStakeHandlers())
|
|
356
364
|
|
|
357
365
|
const stakes = await fetchStakes()
|
|
@@ -6,10 +6,11 @@ import type { StakingContractConfig } from '../../types/staking'
|
|
|
6
6
|
import type { ValidatorApi } from './types'
|
|
7
7
|
import type { Page } from '@ledgerhq/coin-module-framework/api/index'
|
|
8
8
|
import type { AssetInfo, Stake, Validator } from '@ledgerhq/coin-module-framework/api/types'
|
|
9
|
+
import type { JsonRpcProvider } from 'ethers'
|
|
9
10
|
import network from '@ledgerhq/live-network'
|
|
10
11
|
import { makeLRUCache } from '@ledgerhq/live-network/cache'
|
|
11
12
|
import { log } from '@ledgerhq/logs'
|
|
12
|
-
import { ethers
|
|
13
|
+
import { ethers } from 'ethers'
|
|
13
14
|
import { evmUnit } from '../../logic/evmUnit'
|
|
14
15
|
import { withApi } from '../../network/node/rpc.common'
|
|
15
16
|
import { isExternalNodeConfig } from '../../network/node/types'
|