@ledgerhq/coin-evm 15.0.0 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/lib/adapters/etherscan.d.ts.map +1 -1
- package/lib/adapters/etherscan.js +14 -0
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/adapters/ledger.d.ts.map +1 -1
- package/lib/adapters/ledger.js +2 -0
- package/lib/adapters/ledger.js.map +1 -1
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +14 -15
- package/lib/api/index.js.map +1 -1
- package/lib/chains.d.ts +7 -0
- package/lib/chains.d.ts.map +1 -1
- package/lib/chains.js +17 -1
- package/lib/chains.js.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +2 -1
- package/lib/config.js.map +1 -1
- package/lib/errors.d.ts +11 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +17 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/broadcast.d.ts +1 -1
- package/lib/logic/broadcast.d.ts.map +1 -1
- package/lib/logic/broadcast.js +2 -2
- package/lib/logic/broadcast.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 +3 -3
- package/lib/logic/craftTransaction.js.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 +19 -4
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts +1 -2
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js +5 -6
- 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 +23 -6
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getBlockInfo.d.ts +1 -1
- package/lib/logic/getBlockInfo.d.ts.map +1 -1
- package/lib/logic/getBlockInfo.js +2 -2
- package/lib/logic/getBlockInfo.js.map +1 -1
- package/lib/logic/getNextSequence.d.ts +1 -1
- package/lib/logic/getNextSequence.d.ts.map +1 -1
- package/lib/logic/getNextSequence.js +2 -2
- package/lib/logic/getNextSequence.js.map +1 -1
- package/lib/logic/getStakes.d.ts +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/lastBlock.d.ts +1 -1
- package/lib/logic/lastBlock.d.ts.map +1 -1
- package/lib/logic/lastBlock.js +2 -2
- package/lib/logic/lastBlock.js.map +1 -1
- package/lib/logic/listOperations.d.ts +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +4 -2
- package/lib/logic/listOperations.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 +3 -3
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/logic.js +5 -10
- package/lib/logic.js.map +1 -1
- package/lib/network/node/explorerProxy.d.ts.map +1 -1
- package/lib/network/node/explorerProxy.js +2 -0
- package/lib/network/node/explorerProxy.js.map +1 -1
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js +2 -9
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +18 -9
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +3 -1
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/network/node/types.js.map +1 -1
- package/lib/staking/detectOperationType.js +1 -1
- package/lib/staking/validators/index.d.ts +1 -1
- package/lib/staking/validators/index.d.ts.map +1 -1
- package/lib/staking/validators/index.js +2 -2
- package/lib/staking/validators/index.js.map +1 -1
- package/lib/staking/validators/monadResolver.js +1 -1
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/adapters/etherscan.d.ts.map +1 -1
- package/lib-es/adapters/etherscan.js +14 -0
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/adapters/ledger.d.ts.map +1 -1
- package/lib-es/adapters/ledger.js +2 -0
- package/lib-es/adapters/ledger.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/api/index.js +14 -15
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/chains.d.ts +7 -0
- package/lib-es/chains.d.ts.map +1 -1
- package/lib-es/chains.js +16 -0
- package/lib-es/chains.js.map +1 -1
- package/lib-es/config.d.ts +1 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/errors.d.ts +11 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +15 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/broadcast.d.ts +1 -1
- package/lib-es/logic/broadcast.d.ts.map +1 -1
- package/lib-es/logic/broadcast.js +2 -2
- package/lib-es/logic/broadcast.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 +3 -3
- package/lib-es/logic/craftTransaction.js.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 +19 -4
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts +1 -2
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js +5 -6
- 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 +23 -6
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getBlockInfo.d.ts +1 -1
- package/lib-es/logic/getBlockInfo.d.ts.map +1 -1
- package/lib-es/logic/getBlockInfo.js +2 -2
- package/lib-es/logic/getBlockInfo.js.map +1 -1
- package/lib-es/logic/getNextSequence.d.ts +1 -1
- package/lib-es/logic/getNextSequence.d.ts.map +1 -1
- package/lib-es/logic/getNextSequence.js +2 -2
- package/lib-es/logic/getNextSequence.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/getStakes.js +2 -2
- package/lib-es/logic/getStakes.js.map +1 -1
- package/lib-es/logic/lastBlock.d.ts +1 -1
- package/lib-es/logic/lastBlock.d.ts.map +1 -1
- package/lib-es/logic/lastBlock.js +2 -2
- package/lib-es/logic/lastBlock.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +4 -2
- package/lib-es/logic/listOperations.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 +3 -3
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/logic.js +6 -11
- package/lib-es/logic.js.map +1 -1
- package/lib-es/network/node/explorerProxy.d.ts.map +1 -1
- package/lib-es/network/node/explorerProxy.js +2 -0
- package/lib-es/network/node/explorerProxy.js.map +1 -1
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js +3 -10
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +19 -10
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +3 -1
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/network/node/types.js.map +1 -1
- package/lib-es/staking/detectOperationType.js +1 -1
- package/lib-es/staking/validators/index.d.ts +1 -1
- package/lib-es/staking/validators/index.d.ts.map +1 -1
- package/lib-es/staking/validators/index.js +2 -2
- package/lib-es/staking/validators/index.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.js +1 -1
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/package.json +2 -2
- package/src/adapters/etherscan.test.ts +57 -5
- package/src/adapters/etherscan.ts +15 -0
- package/src/adapters/ledger.test.ts +57 -9
- package/src/adapters/ledger.ts +2 -0
- package/src/api/index.ts +14 -17
- package/src/api/{getBlock.integ.test.ts → tests/getBlock.integ.test.ts} +7 -7
- package/src/api/{index.arbitrum.integ.test.ts → tests/index.arbitrum.integ.test.ts} +4 -4
- package/src/api/{index.arc.integ.test.ts → tests/index.arc.integ.test.ts} +4 -4
- package/src/api/{index.avalanche_c_chain_fuji.integ.test.ts → tests/index.avalanche_c_chain_fuji.integ.test.ts} +4 -4
- package/src/api/{index.cronos.integ.test.ts → tests/index.cronos.integ.test.ts} +4 -4
- package/src/api/{index.flare.integ.test.ts → tests/index.flare.integ.test.ts} +4 -4
- package/src/api/{index.integ.test.ts → tests/index.integ.test.ts} +8 -8
- package/src/api/{index.linea.integ.test.ts → tests/index.linea.integ.test.ts} +4 -4
- package/src/api/{index.monad_testnet.integ.test.ts → tests/index.monad_testnet.integ.test.ts} +5 -5
- package/src/api/{index.optimism.integ.test.ts → tests/index.optimism.integ.test.ts} +4 -4
- package/src/api/{index.rsk.integ.test.ts → tests/index.rsk.integ.test.ts} +4 -4
- package/src/api/{index.shape.integ.test.ts → tests/index.shape.integ.test.ts} +4 -4
- package/src/api/{index.somnia.integ.test.ts → tests/index.somnia.integ.test.ts} +4 -4
- package/src/api/{index.test.ts → tests/index.test.ts} +10 -10
- package/src/api/{index.zksync.integ.test.ts → tests/index.zksync.integ.test.ts} +3 -3
- package/src/chains.ts +17 -0
- package/src/config.ts +1 -1
- package/src/errors.ts +14 -0
- package/src/fixtures/context.fixtures.ts +2 -4
- package/src/logic/broadcast.ts +1 -2
- package/src/logic/craftTransaction.ts +2 -3
- package/src/logic/estimateFees.ts +22 -4
- package/src/logic/getBalance.ts +3 -6
- package/src/logic/getBlock.ts +39 -10
- package/src/logic/getBlockInfo.ts +2 -6
- package/src/logic/getNextSequence.ts +2 -6
- package/src/logic/getStakes.ts +1 -2
- package/src/logic/lastBlock.ts +2 -2
- package/src/logic/listOperations.ts +3 -2
- package/src/logic/tests/broadcast.integ.test.ts +1 -1
- package/src/logic/tests/broadcast.test.ts +5 -5
- package/src/logic/tests/broadcastSource.test.ts +4 -4
- package/src/logic/tests/common.test.ts +1 -1
- package/src/logic/tests/craftTransaction.test.ts +16 -21
- package/src/logic/tests/estimateFees.test.ts +40 -18
- package/src/logic/tests/getBalance.test.ts +20 -23
- package/src/logic/tests/getBlock.test.ts +159 -39
- package/src/logic/tests/getBlockInfo.test.ts +6 -6
- package/src/logic/tests/getNextSequence.test.ts +2 -2
- package/src/logic/tests/getStakes.test.ts +14 -14
- package/src/logic/tests/internalTransactionsFetcher.test.ts +1 -1
- package/src/logic/tests/lastBlock.test.ts +4 -4
- package/src/logic/tests/listOperations.test.ts +51 -55
- package/src/logic/tests/validateIntent.test.ts +39 -61
- package/src/logic/validateIntent.ts +2 -3
- package/src/logic.test.ts +24 -7
- package/src/logic.ts +6 -11
- package/src/network/node/explorerProxy.ts +2 -0
- package/src/network/node/ledger.ts +3 -10
- package/src/network/node/rpc.common.ts +23 -10
- package/src/network/node/types.ts +5 -2
- package/src/network/{explorer → tests/explorer}/etherscan.test.ts +8 -8
- package/src/network/{explorer → tests/explorer}/index.test.ts +11 -11
- package/src/network/{explorer → tests/explorer}/ledger.test.ts +11 -11
- package/src/network/{explorer → tests/explorer}/types.test.ts +1 -1
- package/src/network/{gasTracker → tests/gasTracker}/index.test.ts +3 -3
- package/src/network/{gasTracker → tests/gasTracker}/ledger.test.ts +4 -4
- package/src/network/{gasTracker → tests/gasTracker}/types.test.ts +1 -1
- package/src/network/{node → tests/node}/explorerProxy.test.ts +5 -2
- package/src/network/{node → tests/node}/gethCallTracerToTraceBlockItems.test.ts +4 -4
- package/src/network/{node → tests/node}/index.memoization.test.ts +3 -3
- package/src/network/{node → tests/node}/index.test.ts +3 -3
- package/src/network/{node → tests/node}/ledger.test.ts +9 -6
- package/src/network/{node → tests/node}/node.fixtures.ts +1 -1
- package/src/network/{node → tests/node}/rpc.errors.test.ts +1 -1
- package/src/network/{node → tests/node}/rpc.test.ts +57 -6
- package/src/network/{node → tests/node}/types.test.ts +1 -1
- package/src/network/{node → tests/node}/withNodeSources.test.ts +3 -3
- package/src/network/{withRetries.test.ts → tests/withRetries.test.ts} +2 -2
- package/src/staking/detectOperationType.ts +1 -1
- package/src/staking/redelegations.test.ts +3 -3
- package/src/staking/validators/index.ts +1 -2
- package/src/staking/validators/monadResolver.ts +1 -1
- package/src/staking/validators.integ.test.ts +1 -1
- package/src/staking/validators.test.ts +1 -1
|
@@ -5,12 +5,8 @@ import type { EvmContext } from '../config'
|
|
|
5
5
|
import type { BlockInfo } from '@ledgerhq/coin-module-framework/api/index'
|
|
6
6
|
import { getNodeApi } from '../network/node'
|
|
7
7
|
|
|
8
|
-
export async function getBlockInfo(
|
|
9
|
-
context
|
|
10
|
-
currencyId: string,
|
|
11
|
-
height: number
|
|
12
|
-
): Promise<BlockInfo> {
|
|
13
|
-
const config = await context.config(currencyId)
|
|
8
|
+
export async function getBlockInfo(context: EvmContext, height: number): Promise<BlockInfo> {
|
|
9
|
+
const config = await context.config()
|
|
14
10
|
const api = getNodeApi(config, context.logger)
|
|
15
11
|
const result = await api.getBlockByHeight(height)
|
|
16
12
|
|
|
@@ -4,12 +4,8 @@
|
|
|
4
4
|
import type { EvmContext } from '../config'
|
|
5
5
|
import { getNodeApi } from '../network/node'
|
|
6
6
|
|
|
7
|
-
export async function getNextSequence(
|
|
8
|
-
context
|
|
9
|
-
currencyId: string,
|
|
10
|
-
address: string
|
|
11
|
-
): Promise<bigint> {
|
|
12
|
-
const config = await context.config(currencyId)
|
|
7
|
+
export async function getNextSequence(context: EvmContext, address: string): Promise<bigint> {
|
|
8
|
+
const config = await context.config()
|
|
13
9
|
const txCount = await getNodeApi(config, context.logger).getTransactionCount(address)
|
|
14
10
|
return typeof txCount === 'number' ? BigInt(txCount) : txCount
|
|
15
11
|
}
|
package/src/logic/getStakes.ts
CHANGED
|
@@ -8,12 +8,11 @@ import { fetchUnbondings } from '../staking/unbondings'
|
|
|
8
8
|
|
|
9
9
|
export const getStakes = async (
|
|
10
10
|
context: EvmContext,
|
|
11
|
-
currencyId: string,
|
|
12
11
|
address: string,
|
|
13
12
|
options?: StakesOptions
|
|
14
13
|
): Promise<Page<Stake>> => {
|
|
15
14
|
try {
|
|
16
|
-
const config = await context.config(
|
|
15
|
+
const config = await context.config()
|
|
17
16
|
const contractConfig = STAKING_CONTRACTS[config.chainId]
|
|
18
17
|
if (!contractConfig) {
|
|
19
18
|
return { items: [] }
|
package/src/logic/lastBlock.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { EvmContext } from '../config'
|
|
|
5
5
|
import type { BlockInfo } from '@ledgerhq/coin-module-framework/api/index'
|
|
6
6
|
import { getNodeApi } from '../network/node'
|
|
7
7
|
|
|
8
|
-
export async function lastBlock(context: EvmContext
|
|
9
|
-
const config = await context.config(
|
|
8
|
+
export async function lastBlock(context: EvmContext): Promise<BlockInfo> {
|
|
9
|
+
const config = await context.config()
|
|
10
10
|
const api = getNodeApi(config, context.logger)
|
|
11
11
|
const { finalizationLevel = 'latest' } = config
|
|
12
12
|
const result = await api.getBlockByHeight(finalizationLevel)
|
|
@@ -44,7 +44,6 @@ function typeFromAddressPerspective(
|
|
|
44
44
|
|
|
45
45
|
export async function listOperations(
|
|
46
46
|
context: EvmContext,
|
|
47
|
-
currencyId: string,
|
|
48
47
|
address: string,
|
|
49
48
|
options: ListOperationsOptions
|
|
50
49
|
): Promise<Page<Operation<MemoNotSupported>>> {
|
|
@@ -59,7 +58,7 @@ export async function listOperations(
|
|
|
59
58
|
)
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
const config = await context.config(
|
|
61
|
+
const config = await context.config()
|
|
63
62
|
const explorerApi = getExplorerApi(config)
|
|
64
63
|
const explorerOrder = options.limit === undefined ? 'desc' : (options.order ?? 'desc')
|
|
65
64
|
const {
|
|
@@ -146,6 +145,8 @@ export async function listOperations(
|
|
|
146
145
|
details: {
|
|
147
146
|
...(op.details ?? {}),
|
|
148
147
|
sequence: op.details?.sequence ?? parent.details?.sequence,
|
|
148
|
+
gasPrice: op.details?.gasPrice ?? parent.details?.gasPrice,
|
|
149
|
+
gasLimit: op.details?.gasLimit ?? parent.details?.gasLimit,
|
|
149
150
|
parentSenders: parent.senders,
|
|
150
151
|
parentRecipients: parent.recipients,
|
|
151
152
|
...parentContractDetails,
|
|
@@ -46,7 +46,7 @@ describe('Broadcast', () => {
|
|
|
46
46
|
}
|
|
47
47
|
const signature = await wallet.signTransaction(tx)
|
|
48
48
|
|
|
49
|
-
await expect(broadcast(contextForNetwork(network),
|
|
49
|
+
await expect(broadcast(contextForNetwork(network), { signature })).rejects.toThrow(
|
|
50
50
|
/insufficient funds for gas \* price \+ value|InsufficientFunds/
|
|
51
51
|
)
|
|
52
52
|
})
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { mockEvmContext } from '../../fixtures/context.fixtures'
|
|
5
5
|
import { getNodeApi } from '../../network/node/index'
|
|
6
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
6
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
7
7
|
import { broadcast } from '../broadcast'
|
|
8
8
|
|
|
9
9
|
jest.mock('../../network/node/index', () => ({
|
|
@@ -23,7 +23,7 @@ describe('broadcastLogic', () => {
|
|
|
23
23
|
|
|
24
24
|
it('should call getNodeApi and broadcastTransaction with correct arguments', async () => {
|
|
25
25
|
nodeApiMock.broadcastTransaction.mockResolvedValue('txid123')
|
|
26
|
-
const result = await broadcast(mockEvmContext,
|
|
26
|
+
const result = await broadcast(mockEvmContext, {
|
|
27
27
|
signature: '0xabcdef',
|
|
28
28
|
broadcastConfig: { mevProtected: true },
|
|
29
29
|
})
|
|
@@ -37,7 +37,7 @@ describe('broadcastLogic', () => {
|
|
|
37
37
|
it('should propagate errors from broadcastTransaction', async () => {
|
|
38
38
|
nodeApiMock.broadcastTransaction.mockRejectedValue(new Error('Broadcast failed'))
|
|
39
39
|
await expect(
|
|
40
|
-
broadcast(mockEvmContext,
|
|
40
|
+
broadcast(mockEvmContext, {
|
|
41
41
|
signature: '0xabcdef',
|
|
42
42
|
broadcastConfig: { mevProtected: true },
|
|
43
43
|
})
|
|
@@ -46,7 +46,7 @@ describe('broadcastLogic', () => {
|
|
|
46
46
|
|
|
47
47
|
it('should handle undefined broadcastConfig', async () => {
|
|
48
48
|
nodeApiMock.broadcastTransaction.mockResolvedValue('txid456')
|
|
49
|
-
const result = await broadcast(mockEvmContext,
|
|
49
|
+
const result = await broadcast(mockEvmContext, {
|
|
50
50
|
signature: '0xabcdef',
|
|
51
51
|
broadcastConfig: undefined,
|
|
52
52
|
})
|
|
@@ -56,7 +56,7 @@ describe('broadcastLogic', () => {
|
|
|
56
56
|
|
|
57
57
|
it('should handle different signature values', async () => {
|
|
58
58
|
nodeApiMock.broadcastTransaction.mockResolvedValue('txid789')
|
|
59
|
-
const result = await broadcast(mockEvmContext,
|
|
59
|
+
const result = await broadcast(mockEvmContext, {
|
|
60
60
|
signature: '0x123456',
|
|
61
61
|
broadcastConfig: { mevProtected: true },
|
|
62
62
|
})
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { mockEvmContext } from '../../fixtures/context.fixtures'
|
|
5
5
|
import { getNodeApi } from '../../network/node/index'
|
|
6
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
6
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
7
7
|
import { broadcast } from '../broadcast'
|
|
8
8
|
|
|
9
9
|
jest.mock('../../network/node/index', () => ({
|
|
@@ -23,7 +23,7 @@ describe('EVM broadcast with source', () => {
|
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
it('should broadcast with source headers from broadcastConfig', async () => {
|
|
26
|
-
const result = await broadcast(mockEvmContext,
|
|
26
|
+
const result = await broadcast(mockEvmContext, {
|
|
27
27
|
signature: '0xsignature',
|
|
28
28
|
broadcastConfig: {
|
|
29
29
|
mevProtected: true,
|
|
@@ -48,7 +48,7 @@ describe('EVM broadcast with source', () => {
|
|
|
48
48
|
})
|
|
49
49
|
|
|
50
50
|
it('should broadcast swap transaction with swap source', async () => {
|
|
51
|
-
const result = await broadcast(mockEvmContext,
|
|
51
|
+
const result = await broadcast(mockEvmContext, {
|
|
52
52
|
signature: '0xsignature',
|
|
53
53
|
broadcastConfig: {
|
|
54
54
|
mevProtected: false,
|
|
@@ -73,7 +73,7 @@ describe('EVM broadcast with source', () => {
|
|
|
73
73
|
})
|
|
74
74
|
|
|
75
75
|
it('should broadcast without source when not provided', async () => {
|
|
76
|
-
const result = await broadcast(mockEvmContext,
|
|
76
|
+
const result = await broadcast(mockEvmContext, {
|
|
77
77
|
signature: '0xsignature',
|
|
78
78
|
broadcastConfig: {
|
|
79
79
|
mevProtected: false,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
testLogger,
|
|
16
16
|
} from '../../fixtures/context.fixtures'
|
|
17
17
|
import { getNodeApi } from '../../network/node'
|
|
18
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
18
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
19
19
|
import { buildStakingTransactionParams } from '../../staking'
|
|
20
20
|
import { USEI_TO_EVM_SCALE } from '../../staking/utils'
|
|
21
21
|
import { getCallData, prepareUnsignedTxParams } from '../common'
|
|
@@ -12,7 +12,7 @@ import { ethers } from 'ethers'
|
|
|
12
12
|
import { CHAIN_ID } from '../../config'
|
|
13
13
|
import { createMockEvmContext, mkExternalNode, mkLedgerNode } from '../../fixtures/context.fixtures'
|
|
14
14
|
import { getNodeApi } from '../../network/node'
|
|
15
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
15
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
16
16
|
import { craftTransaction } from '../craftTransaction'
|
|
17
17
|
|
|
18
18
|
jest.mock('../../network/node', () => ({
|
|
@@ -37,7 +37,7 @@ describe('craftTransaction', () => {
|
|
|
37
37
|
|
|
38
38
|
it('fails to craft an unknown intent type', async () => {
|
|
39
39
|
await expect(
|
|
40
|
-
craftTransaction(createMockEvmContext(),
|
|
40
|
+
craftTransaction(createMockEvmContext(), {
|
|
41
41
|
// @ts-ignore — intentionally invalid intent type to test the unsupported-type error path
|
|
42
42
|
transactionIntent: { type: 'any' },
|
|
43
43
|
})
|
|
@@ -69,7 +69,6 @@ describe('craftTransaction', () => {
|
|
|
69
69
|
|
|
70
70
|
const { transaction } = await craftTransaction(
|
|
71
71
|
createMockEvmContext({ node: mkExternalNode(), chainId: 42 }),
|
|
72
|
-
'ethereum',
|
|
73
72
|
{
|
|
74
73
|
transactionIntent: intent,
|
|
75
74
|
customFees: { value: 0n, parameters: { gasPrice: 8n, gasLimit: 0n } },
|
|
@@ -84,14 +83,10 @@ describe('craftTransaction', () => {
|
|
|
84
83
|
externalMocks.getGasEstimation.mockRejectedValue(new Error('node is down'))
|
|
85
84
|
|
|
86
85
|
await expect(
|
|
87
|
-
craftTransaction(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
transactionIntent: intent,
|
|
92
|
-
customFees: { value: 0n, parameters: { gasPrice: 8n } },
|
|
93
|
-
}
|
|
94
|
-
)
|
|
86
|
+
craftTransaction(createMockEvmContext({ node: mkExternalNode(), chainId: 42 }), {
|
|
87
|
+
transactionIntent: intent,
|
|
88
|
+
customFees: { value: 0n, parameters: { gasPrice: 8n } },
|
|
89
|
+
})
|
|
95
90
|
).rejects.toThrow('GasEstimationError')
|
|
96
91
|
})
|
|
97
92
|
})
|
|
@@ -134,7 +129,7 @@ describe('craftTransaction', () => {
|
|
|
134
129
|
mocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
|
|
135
130
|
mocks.getFeeData.mockResolvedValue(feeData)
|
|
136
131
|
|
|
137
|
-
const { transaction } = await craftTransaction(context,
|
|
132
|
+
const { transaction } = await craftTransaction(context, {
|
|
138
133
|
transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
139
134
|
type: `send-${transactionType}`,
|
|
140
135
|
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
@@ -172,7 +167,7 @@ describe('craftTransaction', () => {
|
|
|
172
167
|
mocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
|
|
173
168
|
mocks.getFeeData.mockResolvedValue(feeData)
|
|
174
169
|
|
|
175
|
-
const { transaction } = await craftTransaction(context,
|
|
170
|
+
const { transaction } = await craftTransaction(context, {
|
|
176
171
|
transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
177
172
|
type: `send-${transactionType}`,
|
|
178
173
|
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
@@ -219,7 +214,7 @@ describe('craftTransaction', () => {
|
|
|
219
214
|
const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
|
|
220
215
|
mocks.getTransactionCount.mockResolvedValue(18)
|
|
221
216
|
|
|
222
|
-
const { transaction } = await craftTransaction(context,
|
|
217
|
+
const { transaction } = await craftTransaction(context, {
|
|
223
218
|
transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
224
219
|
type: `send-${transactionType}`,
|
|
225
220
|
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
@@ -280,7 +275,7 @@ describe('craftTransaction', () => {
|
|
|
280
275
|
nextBaseFee: null,
|
|
281
276
|
})
|
|
282
277
|
|
|
283
|
-
const { transaction } = await craftTransaction(context,
|
|
278
|
+
const { transaction } = await craftTransaction(context, {
|
|
284
279
|
transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
285
280
|
type: 'send-legacy',
|
|
286
281
|
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
@@ -314,7 +309,7 @@ describe('craftTransaction', () => {
|
|
|
314
309
|
nextBaseFee: null,
|
|
315
310
|
})
|
|
316
311
|
|
|
317
|
-
const { transaction } = await craftTransaction(context,
|
|
312
|
+
const { transaction } = await craftTransaction(context, {
|
|
318
313
|
transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
319
314
|
type: 'send-legacy',
|
|
320
315
|
sequence: 15n,
|
|
@@ -385,7 +380,7 @@ describe('craftTransaction', () => {
|
|
|
385
380
|
mocks.getGasEstimation.mockResolvedValue(new BigNumber(45000))
|
|
386
381
|
mocks.getFeeData.mockResolvedValue(feeData)
|
|
387
382
|
|
|
388
|
-
const { transaction } = await craftTransaction(context,
|
|
383
|
+
const { transaction } = await craftTransaction(context, {
|
|
389
384
|
transactionIntent: createStakingTransactionIntentMockData<
|
|
390
385
|
MemoNotSupported,
|
|
391
386
|
BufferTxData
|
|
@@ -427,7 +422,7 @@ describe('craftTransaction', () => {
|
|
|
427
422
|
mocks.getGasEstimation.mockResolvedValue(new BigNumber(50000))
|
|
428
423
|
mocks.getFeeData.mockResolvedValue(feeData)
|
|
429
424
|
|
|
430
|
-
const { transaction } = await craftTransaction(context,
|
|
425
|
+
const { transaction } = await craftTransaction(context, {
|
|
431
426
|
transactionIntent: createStakingTransactionIntentMockData<
|
|
432
427
|
MemoNotSupported,
|
|
433
428
|
BufferTxData
|
|
@@ -466,7 +461,7 @@ describe('craftTransaction', () => {
|
|
|
466
461
|
mocks.getGasEstimation.mockResolvedValue(new BigNumber(60000))
|
|
467
462
|
mocks.getFeeData.mockResolvedValue(feeData)
|
|
468
463
|
|
|
469
|
-
const { transaction } = await craftTransaction(context,
|
|
464
|
+
const { transaction } = await craftTransaction(context, {
|
|
470
465
|
transactionIntent: createStakingTransactionIntentMockData<
|
|
471
466
|
MemoNotSupported,
|
|
472
467
|
BufferTxData
|
|
@@ -500,7 +495,7 @@ describe('craftTransaction', () => {
|
|
|
500
495
|
const context = createMockEvmContext({ node: mkExternalNode() })
|
|
501
496
|
|
|
502
497
|
await expect(
|
|
503
|
-
craftTransaction(context,
|
|
498
|
+
craftTransaction(context, {
|
|
504
499
|
// @ts-expect-error bare staking intent
|
|
505
500
|
transactionIntent: { type: 'staking', mode: 'delegate' },
|
|
506
501
|
})
|
|
@@ -513,7 +508,7 @@ describe('craftTransaction', () => {
|
|
|
513
508
|
const context = createMockEvmContext({ node: mkExternalNode(), chainId: CHAIN_ID.SEI_EVM })
|
|
514
509
|
|
|
515
510
|
await expect(
|
|
516
|
-
craftTransaction(context,
|
|
511
|
+
craftTransaction(context, {
|
|
517
512
|
transactionIntent: {
|
|
518
513
|
type: 'staking-legacy',
|
|
519
514
|
intentType: 'staking',
|
|
@@ -11,11 +11,11 @@ import type {
|
|
|
11
11
|
import { createSendTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
|
|
12
12
|
import BigNumber from 'bignumber.js'
|
|
13
13
|
import { CHAIN_ID } from '../../config'
|
|
14
|
-
import { GasEstimationError } from '../../errors'
|
|
14
|
+
import { GasEstimationError, L1DataFeeUnavailableError } from '../../errors'
|
|
15
15
|
import { createMockEvmContext } from '../../fixtures/context.fixtures'
|
|
16
16
|
import { getGasTracker } from '../../network/gasTracker'
|
|
17
17
|
import { getNodeApi } from '../../network/node'
|
|
18
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
18
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
19
19
|
import { estimateFees } from '../estimateFees'
|
|
20
20
|
|
|
21
21
|
jest.mock('../../network/node', () => ({
|
|
@@ -55,6 +55,7 @@ describe('estimateFees', () => {
|
|
|
55
55
|
})
|
|
56
56
|
const optimismContext: EvmContext = createMockEvmContext({
|
|
57
57
|
chainId: CHAIN_ID.OPTIMISM,
|
|
58
|
+
name: 'OP Mainnet',
|
|
58
59
|
gasTracker: { type: 'ledger', explorerId: 'eth' },
|
|
59
60
|
})
|
|
60
61
|
const seiContext: EvmContext = createMockEvmContext({
|
|
@@ -72,7 +73,6 @@ describe('estimateFees', () => {
|
|
|
72
73
|
expect(
|
|
73
74
|
await estimateFees(
|
|
74
75
|
context,
|
|
75
|
-
'ethereum',
|
|
76
76
|
createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
|
|
77
77
|
type: 'send-legacy',
|
|
78
78
|
recipient: 'not-an-address',
|
|
@@ -88,7 +88,6 @@ describe('estimateFees', () => {
|
|
|
88
88
|
|
|
89
89
|
const result = await estimateFees(
|
|
90
90
|
context,
|
|
91
|
-
'ethereum',
|
|
92
91
|
{
|
|
93
92
|
intentType: 'transaction',
|
|
94
93
|
type: 'send-legacy',
|
|
@@ -185,7 +184,6 @@ describe('estimateFees', () => {
|
|
|
185
184
|
|
|
186
185
|
const result = await estimateFees(
|
|
187
186
|
context,
|
|
188
|
-
'ethereum',
|
|
189
187
|
{
|
|
190
188
|
intentType: 'transaction',
|
|
191
189
|
type: 'send-legacy',
|
|
@@ -248,7 +246,6 @@ describe('estimateFees', () => {
|
|
|
248
246
|
|
|
249
247
|
const result = await estimateFees(
|
|
250
248
|
context,
|
|
251
|
-
'ethereum',
|
|
252
249
|
{
|
|
253
250
|
intentType: 'transaction',
|
|
254
251
|
type: 'send-eip1559',
|
|
@@ -279,7 +276,6 @@ describe('estimateFees', () => {
|
|
|
279
276
|
nodeApiMock.getTransactionCount.mockResolvedValue(42)
|
|
280
277
|
const result = await estimateFees(
|
|
281
278
|
context,
|
|
282
|
-
'ethereum',
|
|
283
279
|
{
|
|
284
280
|
intentType: 'transaction',
|
|
285
281
|
type: 'send-legacy',
|
|
@@ -321,7 +317,6 @@ describe('estimateFees', () => {
|
|
|
321
317
|
|
|
322
318
|
const result = await estimateFees(
|
|
323
319
|
context,
|
|
324
|
-
'ethereum',
|
|
325
320
|
{
|
|
326
321
|
intentType: 'transaction',
|
|
327
322
|
type: 'send-legacy',
|
|
@@ -360,7 +355,6 @@ describe('estimateFees', () => {
|
|
|
360
355
|
|
|
361
356
|
const result = await estimateFees(
|
|
362
357
|
context,
|
|
363
|
-
'ethereum',
|
|
364
358
|
{
|
|
365
359
|
intentType: 'transaction',
|
|
366
360
|
type: 'send-legacy',
|
|
@@ -398,7 +392,7 @@ describe('estimateFees', () => {
|
|
|
398
392
|
mockGetGasTracker.mockReturnValue(null)
|
|
399
393
|
nodeApiMock.getOptimismAdditionalFees.mockResolvedValue(new BigNumber(8000))
|
|
400
394
|
|
|
401
|
-
const result = await estimateFees(optimismContext,
|
|
395
|
+
const result = await estimateFees(optimismContext, {
|
|
402
396
|
intentType: 'transaction',
|
|
403
397
|
type: 'send-legacy',
|
|
404
398
|
amount: BigInt('1000000000000000000'),
|
|
@@ -433,7 +427,7 @@ describe('estimateFees', () => {
|
|
|
433
427
|
mockGetGasTracker.mockReturnValue(null)
|
|
434
428
|
nodeApiMock.getOptimismAdditionalFees.mockResolvedValue(new BigNumber(8000))
|
|
435
429
|
|
|
436
|
-
const result = await estimateFees(optimismContext,
|
|
430
|
+
const result = await estimateFees(optimismContext, {
|
|
437
431
|
intentType: 'transaction',
|
|
438
432
|
type: 'send-legacy',
|
|
439
433
|
amount: BigInt('1000000000000000000'),
|
|
@@ -447,6 +441,36 @@ describe('estimateFees', () => {
|
|
|
447
441
|
expect(result.parameters?.additionalFees).toBe(16000n)
|
|
448
442
|
})
|
|
449
443
|
|
|
444
|
+
it('fails with an explicit error when the L1 data fee oracle cannot be read', async () => {
|
|
445
|
+
nodeApiMock.getGasEstimation.mockResolvedValue(new BigNumber('21000'))
|
|
446
|
+
nodeApiMock.getTransactionCount.mockResolvedValue(42)
|
|
447
|
+
nodeApiMock.getFeeData.mockResolvedValue({
|
|
448
|
+
gasPrice: new BigNumber('20000000000'),
|
|
449
|
+
maxFeePerGas: null,
|
|
450
|
+
maxPriorityFeePerGas: null,
|
|
451
|
+
nextBaseFee: null,
|
|
452
|
+
})
|
|
453
|
+
mockGetGasTracker.mockReturnValue(null)
|
|
454
|
+
nodeApiMock.getOptimismAdditionalFees.mockRejectedValue(new Error('node unreachable'))
|
|
455
|
+
|
|
456
|
+
const estimation = estimateFees(optimismContext, 'optimism', {
|
|
457
|
+
intentType: 'transaction',
|
|
458
|
+
type: 'send-legacy',
|
|
459
|
+
amount: BigInt('1000000000000000000'),
|
|
460
|
+
asset: { type: 'native' },
|
|
461
|
+
recipient: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
|
|
462
|
+
sender: '0xsender',
|
|
463
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
await expect(estimation).rejects.toThrow(L1DataFeeUnavailableError)
|
|
467
|
+
await expect(estimation).rejects.toMatchObject({
|
|
468
|
+
statusCode: 503,
|
|
469
|
+
chainId: CHAIN_ID.OPTIMISM,
|
|
470
|
+
message: 'Could not get the L1 data fee for chain OP Mainnet: node unreachable',
|
|
471
|
+
})
|
|
472
|
+
})
|
|
473
|
+
|
|
450
474
|
it('gives 0 additional fees if the transaction is not serializable', async () => {
|
|
451
475
|
nodeApiMock.getGasEstimation.mockResolvedValue(new BigNumber('21000'))
|
|
452
476
|
nodeApiMock.getTransactionCount.mockResolvedValue(42)
|
|
@@ -459,7 +483,7 @@ describe('estimateFees', () => {
|
|
|
459
483
|
mockGetGasTracker.mockReturnValue(null)
|
|
460
484
|
nodeApiMock.getOptimismAdditionalFees.mockResolvedValue(new BigNumber(8000))
|
|
461
485
|
|
|
462
|
-
const result = await estimateFees(optimismContext,
|
|
486
|
+
const result = await estimateFees(optimismContext, {
|
|
463
487
|
intentType: 'transaction',
|
|
464
488
|
type: 'send-legacy',
|
|
465
489
|
amount: BigInt('1000000000000000000'),
|
|
@@ -503,7 +527,7 @@ describe('estimateFees', () => {
|
|
|
503
527
|
valAddress: 'seivaloper1y82m5y3wevjneamzg0pmx87dzanyxzht0kepvn',
|
|
504
528
|
amount: 1000000n,
|
|
505
529
|
}
|
|
506
|
-
const result = await estimateFees(seiContext,
|
|
530
|
+
const result = await estimateFees(seiContext, tokenIntent)
|
|
507
531
|
expect(result).toEqual({
|
|
508
532
|
value: 420000000000000n,
|
|
509
533
|
parameters: {
|
|
@@ -537,7 +561,7 @@ describe('estimateFees', () => {
|
|
|
537
561
|
amount: 1000000n,
|
|
538
562
|
useAllAmount: true,
|
|
539
563
|
}
|
|
540
|
-
const result = await estimateFees(seiContext,
|
|
564
|
+
const result = await estimateFees(seiContext, delegateMaxIntent)
|
|
541
565
|
expect(result.parameters).toMatchObject({
|
|
542
566
|
reserve: 10n ** 17n, // 0.1 SEI reserve
|
|
543
567
|
amountScale: 10n ** 12n, // usei -> wei scale
|
|
@@ -555,7 +579,7 @@ describe('estimateFees', () => {
|
|
|
555
579
|
amount: 1000000n,
|
|
556
580
|
}
|
|
557
581
|
|
|
558
|
-
const result = await estimateFees(seiContext,
|
|
582
|
+
const result = await estimateFees(seiContext, redelegateNoDst)
|
|
559
583
|
|
|
560
584
|
expect(result).toEqual({ value: 0n })
|
|
561
585
|
expect(mockGetNodeApi).not.toHaveBeenCalled()
|
|
@@ -582,7 +606,7 @@ describe('estimateFees', () => {
|
|
|
582
606
|
dstValAddress: 'selfvaloper1uvdqeduxvtchfphueyxraag9qkf8zfznzxs30y',
|
|
583
607
|
amount: 1000000n,
|
|
584
608
|
}
|
|
585
|
-
const result = await estimateFees(seiContext,
|
|
609
|
+
const result = await estimateFees(seiContext, tokenIntent)
|
|
586
610
|
expect(result).toEqual({
|
|
587
611
|
value: 420000000000000n,
|
|
588
612
|
parameters: {
|
|
@@ -605,7 +629,6 @@ describe('estimateFees', () => {
|
|
|
605
629
|
|
|
606
630
|
const result = await estimateFees(
|
|
607
631
|
context,
|
|
608
|
-
'ethereum',
|
|
609
632
|
{
|
|
610
633
|
intentType: 'transaction',
|
|
611
634
|
type: 'send-legacy',
|
|
@@ -646,7 +669,6 @@ describe('estimateFees', () => {
|
|
|
646
669
|
|
|
647
670
|
const result = await estimateFees(
|
|
648
671
|
context,
|
|
649
|
-
'ethereum',
|
|
650
672
|
{
|
|
651
673
|
intentType: 'transaction',
|
|
652
674
|
type: 'send-legacy',
|