@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
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { EvmConfigInfo } from '../config'
|
|
5
|
+
import type { BufferTxData, MemoNotSupported } from '@ledgerhq/coin-module-framework/api/types'
|
|
5
6
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from '@ledgerhq/coin-module-framework/api/types'
|
|
7
|
+
createSendTransactionIntentMockData,
|
|
8
|
+
createStakingTransactionIntentMockData,
|
|
9
|
+
} from '@ledgerhq/coin-module-framework/test-utils'
|
|
10
10
|
import BigNumber from 'bignumber.js'
|
|
11
11
|
import { ethers } from 'ethers'
|
|
12
|
-
import { createMockEvmContext } from '../fixtures/context.fixtures'
|
|
12
|
+
import { createMockEvmContext, mkExternalNode, mkLedgerNode } from '../fixtures/context.fixtures'
|
|
13
13
|
import { getNodeApi } from '../network/node'
|
|
14
14
|
import { mockNodeApi } from '../network/node/node.fixtures'
|
|
15
15
|
import { craftTransaction } from './craftTransaction'
|
|
@@ -21,6 +21,9 @@ jest.mock('../network/node', () => ({
|
|
|
21
21
|
|
|
22
22
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
23
23
|
|
|
24
|
+
const nodeFor = (type: 'external' | 'ledger') =>
|
|
25
|
+
type === 'external' ? mkExternalNode() : mkLedgerNode()
|
|
26
|
+
|
|
24
27
|
describe('craftTransaction', () => {
|
|
25
28
|
const externalMocks = mockNodeApi()
|
|
26
29
|
const ledgerMocks = mockNodeApi()
|
|
@@ -34,21 +37,21 @@ describe('craftTransaction', () => {
|
|
|
34
37
|
it('fails to craft an unknown intent type', async () => {
|
|
35
38
|
await expect(
|
|
36
39
|
craftTransaction(createMockEvmContext(), 'ethereum', {
|
|
40
|
+
// @ts-ignore — intentionally invalid intent type to test the unsupported-type error path
|
|
37
41
|
transactionIntent: { type: 'any' },
|
|
38
|
-
}
|
|
42
|
+
})
|
|
39
43
|
).rejects.toThrow(
|
|
40
44
|
"Unsupported intent type 'any'. Must be 'send-legacy', 'send-eip1559', 'staking-legacy', or 'staking-eip1559'"
|
|
41
45
|
)
|
|
42
46
|
})
|
|
43
47
|
|
|
44
48
|
describe('zero gas limit', () => {
|
|
45
|
-
const intent = {
|
|
46
|
-
intentType: 'transaction',
|
|
49
|
+
const intent = createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
47
50
|
type: 'send-legacy',
|
|
48
51
|
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
49
52
|
amount: 10n,
|
|
50
53
|
asset: { type: 'native' },
|
|
51
|
-
}
|
|
54
|
+
})
|
|
52
55
|
|
|
53
56
|
beforeEach(() => {
|
|
54
57
|
externalMocks.getTransactionCount.mockResolvedValue(18)
|
|
@@ -64,7 +67,7 @@ describe('craftTransaction', () => {
|
|
|
64
67
|
externalMocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
|
|
65
68
|
|
|
66
69
|
const { transaction } = await craftTransaction(
|
|
67
|
-
createMockEvmContext({ node:
|
|
70
|
+
createMockEvmContext({ node: mkExternalNode(), chainId: 42 }),
|
|
68
71
|
'ethereum',
|
|
69
72
|
{
|
|
70
73
|
transactionIntent: intent,
|
|
@@ -81,10 +84,7 @@ describe('craftTransaction', () => {
|
|
|
81
84
|
|
|
82
85
|
await expect(
|
|
83
86
|
craftTransaction(
|
|
84
|
-
createMockEvmContext({
|
|
85
|
-
node: { type: 'external' },
|
|
86
|
-
chainId: 42,
|
|
87
|
-
} as Partial<EvmConfigInfo>),
|
|
87
|
+
createMockEvmContext({ node: mkExternalNode(), chainId: 42 }),
|
|
88
88
|
'ethereum',
|
|
89
89
|
{
|
|
90
90
|
transactionIntent: intent,
|
|
@@ -121,131 +121,67 @@ describe('craftTransaction', () => {
|
|
|
121
121
|
maxPriorityFeePerGas: 4,
|
|
122
122
|
},
|
|
123
123
|
],
|
|
124
|
-
]
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
[
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
chainId: 42
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
mocks.getFeeData.mockResolvedValue(feeData)
|
|
136
|
-
|
|
137
|
-
const { transaction } = await craftTransaction(context, 'ethereum', {
|
|
138
|
-
transactionIntent: {
|
|
139
|
-
intentType: 'transaction',
|
|
140
|
-
type: `send-${transactionType}`,
|
|
141
|
-
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
142
|
-
amount: 10n,
|
|
143
|
-
asset: { type: 'native' },
|
|
144
|
-
} as TransactionIntent<MemoNotSupported, BufferTxData>,
|
|
145
|
-
customFees: {
|
|
146
|
-
value: 0n,
|
|
147
|
-
parameters: {
|
|
148
|
-
gasPrice: 8n,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
expect(transaction).toEqual(
|
|
154
|
-
ethers.Transaction.from({
|
|
155
|
-
type: transactionTypeNumber,
|
|
156
|
-
to: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
157
|
-
nonce: 18,
|
|
158
|
-
gasLimit: 2300,
|
|
159
|
-
data: '0x',
|
|
160
|
-
value: 10,
|
|
161
|
-
chainId: 42,
|
|
162
|
-
...expectedFee,
|
|
163
|
-
}).unsignedSerialized
|
|
164
|
-
)
|
|
165
|
-
})
|
|
124
|
+
] as const)(
|
|
125
|
+
'%s transaction type',
|
|
126
|
+
(transactionType, transactionTypeNumber, feeData, expectedFee) => {
|
|
127
|
+
it.each([
|
|
128
|
+
['an external node', 'external', externalMocks],
|
|
129
|
+
['a ledger node', 'ledger', ledgerMocks],
|
|
130
|
+
] as const)('crafts a transaction with the native asset using %s', async (_, type, mocks) => {
|
|
131
|
+
const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
|
|
132
|
+
mocks.getTransactionCount.mockResolvedValue(18)
|
|
133
|
+
mocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
|
|
134
|
+
mocks.getFeeData.mockResolvedValue(feeData)
|
|
166
135
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const { transaction } = await craftTransaction(context, 'ethereum', {
|
|
180
|
-
transactionIntent: {
|
|
181
|
-
intentType: 'transaction',
|
|
182
|
-
type: `send-${transactionType}`,
|
|
183
|
-
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
184
|
-
amount: 10n,
|
|
185
|
-
asset: { type: 'erc20', assetReference: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' },
|
|
186
|
-
} as TransactionIntent<MemoNotSupported, BufferTxData>,
|
|
187
|
-
customFees: {
|
|
188
|
-
value: 0n,
|
|
189
|
-
parameters: {
|
|
190
|
-
gasPrice: 8n,
|
|
136
|
+
const { transaction } = await craftTransaction(context, 'ethereum', {
|
|
137
|
+
transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
138
|
+
type: `send-${transactionType}`,
|
|
139
|
+
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
140
|
+
amount: 10n,
|
|
141
|
+
asset: { type: 'native' },
|
|
142
|
+
}),
|
|
143
|
+
customFees: {
|
|
144
|
+
value: 0n,
|
|
145
|
+
parameters: {
|
|
146
|
+
gasPrice: 8n,
|
|
147
|
+
},
|
|
191
148
|
},
|
|
192
|
-
}
|
|
193
|
-
})
|
|
149
|
+
})
|
|
194
150
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
'hex'
|
|
209
|
-
), // amount
|
|
210
|
-
]).toString('hex'),
|
|
211
|
-
value: 0,
|
|
212
|
-
chainId: 42,
|
|
213
|
-
...expectedFee,
|
|
214
|
-
}).unsignedSerialized
|
|
215
|
-
)
|
|
216
|
-
})
|
|
151
|
+
expect(transaction).toEqual(
|
|
152
|
+
ethers.Transaction.from({
|
|
153
|
+
type: transactionTypeNumber,
|
|
154
|
+
to: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
155
|
+
nonce: 18,
|
|
156
|
+
gasLimit: 2300,
|
|
157
|
+
data: '0x',
|
|
158
|
+
value: 10,
|
|
159
|
+
chainId: 42,
|
|
160
|
+
...expectedFee,
|
|
161
|
+
}).unsignedSerialized
|
|
162
|
+
)
|
|
163
|
+
})
|
|
217
164
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
async (_, type, mocks) => {
|
|
224
|
-
const context = createMockEvmContext({
|
|
225
|
-
node: { type },
|
|
226
|
-
chainId: 42,
|
|
227
|
-
} as Partial<EvmConfigInfo>)
|
|
165
|
+
it.each([
|
|
166
|
+
['an external node', 'external', externalMocks],
|
|
167
|
+
['a ledger node', 'ledger', ledgerMocks],
|
|
168
|
+
] as const)('crafts a transaction with a token asset using %s', async (_, type, mocks) => {
|
|
169
|
+
const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
|
|
228
170
|
mocks.getTransactionCount.mockResolvedValue(18)
|
|
171
|
+
mocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
|
|
172
|
+
mocks.getFeeData.mockResolvedValue(feeData)
|
|
229
173
|
|
|
230
174
|
const { transaction } = await craftTransaction(context, 'ethereum', {
|
|
231
|
-
transactionIntent: {
|
|
232
|
-
intentType: 'transaction',
|
|
175
|
+
transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
233
176
|
type: `send-${transactionType}`,
|
|
234
177
|
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
235
178
|
amount: 10n,
|
|
236
|
-
asset: {
|
|
237
|
-
|
|
238
|
-
assetReference: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
239
|
-
},
|
|
240
|
-
} as TransactionIntent<MemoNotSupported, BufferTxData>,
|
|
179
|
+
asset: { type: 'erc20', assetReference: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' },
|
|
180
|
+
}),
|
|
241
181
|
customFees: {
|
|
242
182
|
value: 0n,
|
|
243
183
|
parameters: {
|
|
244
|
-
gasPrice:
|
|
245
|
-
maxFeePerGas: feeData.maxFeePerGas && BigInt(feeData.maxFeePerGas.toFixed()),
|
|
246
|
-
maxPriorityFeePerGas:
|
|
247
|
-
feeData.maxPriorityFeePerGas && BigInt(feeData.maxPriorityFeePerGas.toFixed()),
|
|
248
|
-
gasLimit: 2300n,
|
|
184
|
+
gasPrice: 8n,
|
|
249
185
|
},
|
|
250
186
|
},
|
|
251
187
|
})
|
|
@@ -271,17 +207,69 @@ describe('craftTransaction', () => {
|
|
|
271
207
|
...expectedFee,
|
|
272
208
|
}).unsignedSerialized
|
|
273
209
|
)
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
it.each([
|
|
213
|
+
['an external node', 'external', externalMocks],
|
|
214
|
+
['a ledger node', 'ledger', ledgerMocks],
|
|
215
|
+
] as const)(
|
|
216
|
+
'crafts a transaction without %s when custom fees are passed',
|
|
217
|
+
async (_, type, mocks) => {
|
|
218
|
+
const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
|
|
219
|
+
mocks.getTransactionCount.mockResolvedValue(18)
|
|
220
|
+
|
|
221
|
+
const { transaction } = await craftTransaction(context, 'ethereum', {
|
|
222
|
+
transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
223
|
+
type: `send-${transactionType}`,
|
|
224
|
+
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
225
|
+
amount: 10n,
|
|
226
|
+
asset: {
|
|
227
|
+
type: 'erc20',
|
|
228
|
+
assetReference: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
229
|
+
},
|
|
230
|
+
}),
|
|
231
|
+
customFees: {
|
|
232
|
+
value: 0n,
|
|
233
|
+
parameters: {
|
|
234
|
+
gasPrice: feeData.gasPrice && BigInt(feeData.gasPrice.toFixed()),
|
|
235
|
+
maxFeePerGas: feeData.maxFeePerGas && BigInt(feeData.maxFeePerGas.toFixed()),
|
|
236
|
+
maxPriorityFeePerGas:
|
|
237
|
+
feeData.maxPriorityFeePerGas && BigInt(feeData.maxPriorityFeePerGas.toFixed()),
|
|
238
|
+
gasLimit: 2300n,
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
expect(transaction).toEqual(
|
|
244
|
+
ethers.Transaction.from({
|
|
245
|
+
type: transactionTypeNumber,
|
|
246
|
+
to: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
247
|
+
nonce: 18,
|
|
248
|
+
gasLimit: 2300,
|
|
249
|
+
data:
|
|
250
|
+
'0x' +
|
|
251
|
+
Buffer.concat([
|
|
252
|
+
Buffer.from('a9059cbb000000000000000000000000', 'hex'), // transfer selector
|
|
253
|
+
Buffer.from('7b2c7232f9e38f30e2868f0e5bf311cd83554b5a', 'hex'), // recipient
|
|
254
|
+
Buffer.from(
|
|
255
|
+
'000000000000000000000000000000000000000000000000000000000000000a',
|
|
256
|
+
'hex'
|
|
257
|
+
), // amount
|
|
258
|
+
]).toString('hex'),
|
|
259
|
+
value: 0,
|
|
260
|
+
chainId: 42,
|
|
261
|
+
...expectedFee,
|
|
262
|
+
}).unsignedSerialized
|
|
263
|
+
)
|
|
264
|
+
expect(mocks.getGasEstimation).not.toHaveBeenCalled()
|
|
265
|
+
expect(mocks.getFeeData).not.toHaveBeenCalled()
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
)
|
|
279
270
|
|
|
280
271
|
it('preserves passed calldata', async () => {
|
|
281
|
-
const context = createMockEvmContext({
|
|
282
|
-
node: { type: 'external' },
|
|
283
|
-
chainId: 42,
|
|
284
|
-
} as Partial<EvmConfigInfo>)
|
|
272
|
+
const context = createMockEvmContext({ node: mkExternalNode(), chainId: 42 })
|
|
285
273
|
externalMocks.getTransactionCount.mockResolvedValue(18)
|
|
286
274
|
externalMocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
|
|
287
275
|
externalMocks.getFeeData.mockResolvedValue({
|
|
@@ -292,14 +280,13 @@ describe('craftTransaction', () => {
|
|
|
292
280
|
})
|
|
293
281
|
|
|
294
282
|
const { transaction } = await craftTransaction(context, 'ethereum', {
|
|
295
|
-
transactionIntent: {
|
|
296
|
-
intentType: 'transaction',
|
|
283
|
+
transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
297
284
|
type: 'send-legacy',
|
|
298
285
|
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
299
286
|
amount: 10n,
|
|
300
287
|
data: { type: 'buffer', value: Buffer.from([0xca, 0xfe]) },
|
|
301
288
|
asset: { type: 'native' },
|
|
302
|
-
}
|
|
289
|
+
}),
|
|
303
290
|
})
|
|
304
291
|
|
|
305
292
|
expect(transaction).toEqual(
|
|
@@ -317,10 +304,7 @@ describe('craftTransaction', () => {
|
|
|
317
304
|
})
|
|
318
305
|
|
|
319
306
|
it('preserves passed sequence', async () => {
|
|
320
|
-
const context = createMockEvmContext({
|
|
321
|
-
node: { type: 'external' },
|
|
322
|
-
chainId: 42,
|
|
323
|
-
} as Partial<EvmConfigInfo>)
|
|
307
|
+
const context = createMockEvmContext({ node: mkExternalNode(), chainId: 42 })
|
|
324
308
|
externalMocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
|
|
325
309
|
externalMocks.getFeeData.mockResolvedValue({
|
|
326
310
|
gasPrice: new BigNumber(5),
|
|
@@ -330,14 +314,13 @@ describe('craftTransaction', () => {
|
|
|
330
314
|
})
|
|
331
315
|
|
|
332
316
|
const { transaction } = await craftTransaction(context, 'ethereum', {
|
|
333
|
-
transactionIntent: {
|
|
334
|
-
intentType: 'transaction',
|
|
335
|
-
sequence: 15n,
|
|
317
|
+
transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
336
318
|
type: 'send-legacy',
|
|
319
|
+
sequence: 15n,
|
|
337
320
|
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
338
321
|
amount: 10n,
|
|
339
322
|
asset: { type: 'native' },
|
|
340
|
-
}
|
|
323
|
+
}),
|
|
341
324
|
})
|
|
342
325
|
|
|
343
326
|
expect(transaction).toEqual(
|
|
@@ -384,7 +367,7 @@ describe('craftTransaction', () => {
|
|
|
384
367
|
maxPriorityFeePerGas: 4,
|
|
385
368
|
},
|
|
386
369
|
],
|
|
387
|
-
])(
|
|
370
|
+
] as const)(
|
|
388
371
|
'staking %s transaction type',
|
|
389
372
|
(transactionType, transactionTypeNumber, feeData, _expectedFee) => {
|
|
390
373
|
it.each([
|
|
@@ -393,25 +376,23 @@ describe('craftTransaction', () => {
|
|
|
393
376
|
] as const)(
|
|
394
377
|
'crafts a SEI staking delegate transaction using %s',
|
|
395
378
|
async (_, type, mocks) => {
|
|
396
|
-
const context = createMockEvmContext({
|
|
397
|
-
node: { type },
|
|
398
|
-
chainId: 42,
|
|
399
|
-
} as Partial<EvmConfigInfo>)
|
|
379
|
+
const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
|
|
400
380
|
mocks.getTransactionCount.mockResolvedValue(25)
|
|
401
381
|
mocks.getGasEstimation.mockResolvedValue(new BigNumber(45000))
|
|
402
382
|
mocks.getFeeData.mockResolvedValue(feeData)
|
|
403
383
|
|
|
404
384
|
const { transaction } = await craftTransaction(context, 'sei_evm', {
|
|
405
|
-
transactionIntent:
|
|
406
|
-
|
|
385
|
+
transactionIntent: createStakingTransactionIntentMockData<
|
|
386
|
+
MemoNotSupported,
|
|
387
|
+
BufferTxData
|
|
388
|
+
>({
|
|
407
389
|
type: `staking-${transactionType}`,
|
|
408
|
-
|
|
390
|
+
mode: 'delegate',
|
|
409
391
|
recipient: '0x000000000000000000000000000000000001005',
|
|
410
392
|
valAddress: 'seivaloper1234567890abcdef1234567890abcdef12345678',
|
|
411
|
-
amount: 1000000000000000000n,
|
|
393
|
+
amount: 1000000000000000000n,
|
|
412
394
|
asset: { type: 'native' },
|
|
413
|
-
|
|
414
|
-
} as any,
|
|
395
|
+
}),
|
|
415
396
|
})
|
|
416
397
|
|
|
417
398
|
// Parse the returned transaction to verify its properties
|
|
@@ -434,25 +415,23 @@ describe('craftTransaction', () => {
|
|
|
434
415
|
] as const)(
|
|
435
416
|
'crafts a SEI staking undelegate transaction using %s',
|
|
436
417
|
async (_, type, mocks) => {
|
|
437
|
-
const context = createMockEvmContext({
|
|
438
|
-
node: { type },
|
|
439
|
-
chainId: 42,
|
|
440
|
-
} as Partial<EvmConfigInfo>)
|
|
418
|
+
const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
|
|
441
419
|
mocks.getTransactionCount.mockResolvedValue(26)
|
|
442
420
|
mocks.getGasEstimation.mockResolvedValue(new BigNumber(50000))
|
|
443
421
|
mocks.getFeeData.mockResolvedValue(feeData)
|
|
444
422
|
|
|
445
423
|
const { transaction } = await craftTransaction(context, 'sei_evm', {
|
|
446
|
-
transactionIntent:
|
|
447
|
-
|
|
424
|
+
transactionIntent: createStakingTransactionIntentMockData<
|
|
425
|
+
MemoNotSupported,
|
|
426
|
+
BufferTxData
|
|
427
|
+
>({
|
|
448
428
|
type: `staking-${transactionType}`,
|
|
449
|
-
|
|
429
|
+
mode: 'undelegate',
|
|
450
430
|
recipient: '0x000000000000000000000000000000000001005',
|
|
451
431
|
valAddress: 'seivaloper1234567890abcdef1234567890abcdef12345678',
|
|
452
|
-
amount: 500000000000000000n,
|
|
432
|
+
amount: 500000000000000000n,
|
|
453
433
|
asset: { type: 'native' },
|
|
454
|
-
|
|
455
|
-
} as any,
|
|
434
|
+
}),
|
|
456
435
|
})
|
|
457
436
|
|
|
458
437
|
// Parse the returned transaction to verify its properties
|
|
@@ -475,25 +454,23 @@ describe('craftTransaction', () => {
|
|
|
475
454
|
] as const)(
|
|
476
455
|
'crafts a CELO staking delegate transaction using %s',
|
|
477
456
|
async (_, type, mocks) => {
|
|
478
|
-
const context = createMockEvmContext({
|
|
479
|
-
node: { type },
|
|
480
|
-
chainId: 42220,
|
|
481
|
-
} as Partial<EvmConfigInfo>)
|
|
457
|
+
const context = createMockEvmContext({ node: nodeFor(type), chainId: 42220 })
|
|
482
458
|
mocks.getTransactionCount.mockResolvedValue(30)
|
|
483
459
|
mocks.getGasEstimation.mockResolvedValue(new BigNumber(60000))
|
|
484
460
|
mocks.getFeeData.mockResolvedValue(feeData)
|
|
485
461
|
|
|
486
462
|
const { transaction } = await craftTransaction(context, 'celo', {
|
|
487
|
-
transactionIntent:
|
|
488
|
-
|
|
463
|
+
transactionIntent: createStakingTransactionIntentMockData<
|
|
464
|
+
MemoNotSupported,
|
|
465
|
+
BufferTxData
|
|
466
|
+
>({
|
|
489
467
|
type: `staking-${transactionType}`,
|
|
490
|
-
|
|
468
|
+
mode: 'delegate',
|
|
491
469
|
recipient: '0x55E1A0C8f376964bd339167476063bFED7f213d5',
|
|
492
470
|
valAddress: '0xabcdef1234567890abcdef1234567890abcdef12',
|
|
493
|
-
amount: 100000000000000000000n,
|
|
471
|
+
amount: 100000000000000000000n,
|
|
494
472
|
asset: { type: 'native' },
|
|
495
|
-
|
|
496
|
-
} as any,
|
|
473
|
+
}),
|
|
497
474
|
})
|
|
498
475
|
|
|
499
476
|
// Parse the returned transaction to verify its properties
|
|
@@ -513,21 +490,12 @@ describe('craftTransaction', () => {
|
|
|
513
490
|
)
|
|
514
491
|
|
|
515
492
|
it('fails to craft staking transaction for unsupported currency', async () => {
|
|
516
|
-
const context = createMockEvmContext({
|
|
517
|
-
node: { type: 'external' },
|
|
518
|
-
} as Partial<EvmConfigInfo>)
|
|
493
|
+
const context = createMockEvmContext({ node: mkExternalNode() })
|
|
519
494
|
|
|
520
495
|
await expect(
|
|
496
|
+
// @ts-ignore — intentionally bare staking intent to test unsupported-currency error path
|
|
521
497
|
craftTransaction(context, 'unsupported_network', {
|
|
522
|
-
transactionIntent: {
|
|
523
|
-
type: 'staking',
|
|
524
|
-
sender: '0x1234567890abcdef1234567890abcdef12345678',
|
|
525
|
-
recipient: '0x000000000000000000000000000000000001005',
|
|
526
|
-
valAddress: 'validator123',
|
|
527
|
-
amount: 1000000000000000000n,
|
|
528
|
-
asset: { type: 'native' },
|
|
529
|
-
mode: 'delegate',
|
|
530
|
-
} as any,
|
|
498
|
+
transactionIntent: { type: 'staking', mode: 'delegate' },
|
|
531
499
|
})
|
|
532
500
|
).rejects.toThrow(
|
|
533
501
|
"Unsupported intent type 'staking'. Must be 'send-legacy', 'send-eip1559', 'staking-legacy', or 'staking-eip1559'"
|
|
@@ -535,23 +503,18 @@ describe('craftTransaction', () => {
|
|
|
535
503
|
})
|
|
536
504
|
|
|
537
505
|
it('fails to craft staking transaction with unsupported operation', async () => {
|
|
538
|
-
const context = createMockEvmContext({
|
|
539
|
-
node: { type: 'external' },
|
|
540
|
-
} as Partial<EvmConfigInfo>)
|
|
506
|
+
const context = createMockEvmContext({ node: mkExternalNode() })
|
|
541
507
|
|
|
542
508
|
await expect(
|
|
543
509
|
craftTransaction(context, 'sei_evm', {
|
|
544
510
|
transactionIntent: {
|
|
545
|
-
type: 'staking',
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
valAddress: 'validator123',
|
|
549
|
-
amount: 1000000000000000000n,
|
|
550
|
-
asset: { type: 'native' },
|
|
511
|
+
type: 'staking-legacy',
|
|
512
|
+
intentType: 'staking',
|
|
513
|
+
// @ts-ignore — intentionally invalid staking mode to test unsupported-operation error path
|
|
551
514
|
mode: 'unsupported_operation',
|
|
552
|
-
}
|
|
515
|
+
},
|
|
553
516
|
})
|
|
554
|
-
).rejects.toThrow()
|
|
517
|
+
).rejects.toThrow('Invalid staking operation: unsupported_operation')
|
|
555
518
|
})
|
|
556
519
|
})
|
|
557
520
|
})
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { EvmContext } from '../config'
|
|
5
|
-
import {
|
|
5
|
+
import type {
|
|
6
6
|
BufferTxData,
|
|
7
7
|
CraftedTransaction,
|
|
8
8
|
FeeEstimation,
|
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
MemoNotSupported,
|
|
11
11
|
TransactionIntent,
|
|
12
12
|
} from '@ledgerhq/coin-module-framework/api/types'
|
|
13
|
-
import {
|
|
13
|
+
import type { TransactionLike } from 'ethers'
|
|
14
|
+
import { Transaction } from 'ethers'
|
|
14
15
|
import { GasEstimationError } from '../errors'
|
|
15
16
|
import { getNodeApi } from '../network/node'
|
|
16
17
|
import { TransactionTypes } from '../types'
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
MemoNotSupported,
|
|
7
|
-
BufferTxData,
|
|
8
|
-
} from '@ledgerhq/coin-module-framework/api/types'
|
|
4
|
+
import type { MemoNotSupported, BufferTxData } from '@ledgerhq/coin-module-framework/api/types'
|
|
5
|
+
import { createSendTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
|
|
9
6
|
import * as commonModule from './common'
|
|
10
7
|
import { craftTransactionData } from './craftTransactionData'
|
|
11
8
|
|
|
@@ -24,7 +21,10 @@ describe('craftTransactionData', () => {
|
|
|
24
21
|
.spyOn(commonModule, 'getCallData')
|
|
25
22
|
.mockReturnValueOnce(expectedBuffer)
|
|
26
23
|
|
|
27
|
-
const intent =
|
|
24
|
+
const intent = createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
25
|
+
type: 'send',
|
|
26
|
+
data: { type: 'buffer', value: Buffer.alloc(0) },
|
|
27
|
+
})
|
|
28
28
|
const callData = craftTransactionData(intent)
|
|
29
29
|
|
|
30
30
|
expect(callData).toEqual({
|