@ledgerhq/coin-evm 15.2.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 +24 -0
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +14 -14
- package/lib/api/index.js.map +1 -1
- package/lib/chains.d.ts +6 -0
- package/lib/chains.d.ts.map +1 -1
- package/lib/chains.js +16 -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 +2 -2
- 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 +2 -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/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js +1 -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 +1 -9
- package/lib/network/node/rpc.common.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/api/index.d.ts +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +14 -14
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/chains.d.ts +6 -0
- package/lib-es/chains.d.ts.map +1 -1
- package/lib-es/chains.js +15 -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 +2 -2
- 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 +2 -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/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js +2 -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 +2 -10
- package/lib-es/network/node/rpc.common.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 +1 -1
- package/src/api/index.ts +14 -16
- package/src/api/tests/getBlock.integ.test.ts +3 -3
- package/src/api/tests/index.arbitrum.integ.test.ts +1 -1
- package/src/api/tests/index.arc.integ.test.ts +1 -1
- package/src/api/tests/index.avalanche_c_chain_fuji.integ.test.ts +1 -1
- package/src/api/tests/index.cronos.integ.test.ts +1 -1
- package/src/api/tests/index.flare.integ.test.ts +1 -1
- package/src/api/tests/index.integ.test.ts +5 -5
- package/src/api/tests/index.linea.integ.test.ts +1 -1
- package/src/api/tests/index.monad_testnet.integ.test.ts +1 -1
- package/src/api/tests/index.optimism.integ.test.ts +1 -1
- package/src/api/tests/index.rsk.integ.test.ts +1 -1
- package/src/api/tests/index.shape.integ.test.ts +1 -1
- package/src/api/tests/index.somnia.integ.test.ts +1 -1
- package/src/api/tests/index.test.ts +6 -6
- package/src/api/tests/index.zksync.integ.test.ts +1 -1
- package/src/chains.ts +16 -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 +2 -6
- 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 +1 -2
- package/src/logic/tests/broadcast.integ.test.ts +1 -1
- package/src/logic/tests/broadcast.test.ts +4 -4
- package/src/logic/tests/broadcastSource.test.ts +3 -3
- package/src/logic/tests/craftTransaction.test.ts +15 -20
- package/src/logic/tests/estimateFees.test.ts +39 -17
- package/src/logic/tests/getBalance.test.ts +19 -22
- package/src/logic/tests/getBlock.test.ts +37 -38
- package/src/logic/tests/getBlockInfo.test.ts +5 -5
- package/src/logic/tests/getNextSequence.test.ts +1 -1
- package/src/logic/tests/getStakes.test.ts +14 -14
- package/src/logic/tests/lastBlock.test.ts +3 -3
- package/src/logic/tests/listOperations.test.ts +46 -52
- package/src/logic/tests/validateIntent.test.ts +3 -61
- package/src/logic/validateIntent.ts +2 -3
- package/src/logic.test.ts +23 -6
- package/src/logic.ts +6 -11
- package/src/network/node/ledger.ts +2 -10
- package/src/network/node/rpc.common.ts +2 -10
- package/src/network/tests/explorer/index.test.ts +4 -4
- package/src/network/tests/node/ledger.test.ts +2 -0
- package/src/network/tests/node/rpc.test.ts +42 -0
- 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
|
@@ -23,7 +23,7 @@ describe('Shape (external node)', () => {
|
|
|
23
23
|
},
|
|
24
24
|
supportedTokens: ['erc721', 'erc1155'],
|
|
25
25
|
}
|
|
26
|
-
const module = createApi(
|
|
26
|
+
const module = createApi()
|
|
27
27
|
|
|
28
28
|
it('should return WETH mint from Deposit log in block 26327282 (tx 0x08761e…) see BACK-10995', async () => {
|
|
29
29
|
const weth = '0x4200000000000000000000000000000000000006'
|
|
@@ -54,11 +54,11 @@ describe.each([
|
|
|
54
54
|
],
|
|
55
55
|
])('coin-framework methods %s', (_s, _config, methods) => {
|
|
56
56
|
it('declares every method the chain supports', () => {
|
|
57
|
-
expect(createApi(
|
|
57
|
+
expect(createApi()).toEqual(methods)
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
it('omits the capabilities the chain has none of', () => {
|
|
61
|
-
const impl = createApi(
|
|
61
|
+
const impl = createApi()
|
|
62
62
|
for (const method of ['craftRawTransaction', 'register', 'getStakes', 'getRewards'] as const) {
|
|
63
63
|
expect(impl).not.toHaveProperty(method)
|
|
64
64
|
}
|
|
@@ -118,7 +118,7 @@ describe('parseCallParams', () => {
|
|
|
118
118
|
})
|
|
119
119
|
|
|
120
120
|
it('rejects invalid params as a rejected promise, not a synchronous throw', async () => {
|
|
121
|
-
const api = createApi(
|
|
121
|
+
const api = createApi()
|
|
122
122
|
await expect(api.call(mockEvmContext, {})).rejects.toThrow('Invalid EVM call params')
|
|
123
123
|
})
|
|
124
124
|
})
|
|
@@ -141,12 +141,12 @@ describe('staking support capability', () => {
|
|
|
141
141
|
}
|
|
142
142
|
mockGetValidatorsPage.mockResolvedValue(expectedPage)
|
|
143
143
|
|
|
144
|
-
const api = createApi(
|
|
144
|
+
const api = createApi()
|
|
145
145
|
|
|
146
146
|
await expect(api.getValidators(mockEvmContext)).resolves.toEqual(expectedPage)
|
|
147
|
-
expect(mockGetValidatorsPage).toHaveBeenCalledWith(mockEvmContext,
|
|
147
|
+
expect(mockGetValidatorsPage).toHaveBeenCalledWith(mockEvmContext, undefined)
|
|
148
148
|
|
|
149
149
|
await expect(api.getValidators(mockEvmContext, { cursor: '42' })).resolves.toEqual(expectedPage)
|
|
150
|
-
expect(mockGetValidatorsPage).toHaveBeenCalledWith(mockEvmContext, '
|
|
150
|
+
expect(mockGetValidatorsPage).toHaveBeenCalledWith(mockEvmContext, '42')
|
|
151
151
|
})
|
|
152
152
|
})
|
package/src/chains.ts
CHANGED
|
@@ -96,3 +96,19 @@ export const CHAIN_ID = {
|
|
|
96
96
|
} as const
|
|
97
97
|
|
|
98
98
|
export type ChainId = (typeof CHAIN_ID)[keyof typeof CHAIN_ID]
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* OP Stack chains that bill an L1 data fee on top of L2 execution gas.
|
|
102
|
+
* The fee is read from the GasPriceOracle predeploy (`getL1Fee`).
|
|
103
|
+
* @see https://docs.optimism.io/stack/transactions/fees
|
|
104
|
+
*/
|
|
105
|
+
export const OP_STACK_L1_FEE_CHAIN_IDS: readonly ChainId[] = [
|
|
106
|
+
CHAIN_ID.OPTIMISM,
|
|
107
|
+
CHAIN_ID.OPTIMISM_SEPOLIA,
|
|
108
|
+
CHAIN_ID.BASE,
|
|
109
|
+
CHAIN_ID.BASE_SEPOLIA,
|
|
110
|
+
CHAIN_ID.BLAST,
|
|
111
|
+
CHAIN_ID.BLAST_SEPOLIA,
|
|
112
|
+
CHAIN_ID.SHAPE,
|
|
113
|
+
CHAIN_ID.BOBA,
|
|
114
|
+
]
|
package/src/config.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { InternalTxSourceList } from './internalTxSources'
|
|
|
6
6
|
import type { NodeSourceList } from './nodeSources'
|
|
7
7
|
import type { Context, CurrencyConfig } from '@ledgerhq/coin-module-framework/config'
|
|
8
8
|
|
|
9
|
-
export { CHAIN_ID } from './chains'
|
|
9
|
+
export { CHAIN_ID, OP_STACK_L1_FEE_CHAIN_IDS } from './chains'
|
|
10
10
|
export type { ChainId } from './chains'
|
|
11
11
|
|
|
12
12
|
export type { InternalTxSource, InternalTxSourceList, NonEmptySource } from './internalTxSources'
|
package/src/errors.ts
CHANGED
|
@@ -133,6 +133,20 @@ export class GasPriceTooLow extends Error {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* The L1 data fee of a rollup (e.g. OP Stack `GasPriceOracle.getL1Fee`) could not be read.
|
|
138
|
+
* Raised instead of reporting a zero fee, which would under-estimate the total fee.
|
|
139
|
+
*/
|
|
140
|
+
export class L1DataFeeUnavailableError extends Error {
|
|
141
|
+
override name = 'L1DataFeeUnavailableError'
|
|
142
|
+
readonly statusCode = 503
|
|
143
|
+
constructor(message?: string, fields?: Record<string, unknown>, options?: { cause?: unknown }) {
|
|
144
|
+
super(message || 'L1 data fee is unavailable, please retry later')
|
|
145
|
+
if (fields) Object.assign(this, fields)
|
|
146
|
+
if (options?.cause !== undefined) Object.assign(this, { cause: options.cause })
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
136
150
|
export class GasEstimationError extends Error {
|
|
137
151
|
override name = 'GasEstimationError'
|
|
138
152
|
constructor(message?: string, fields?: Record<string, unknown>) {
|
|
@@ -88,14 +88,12 @@ export const createMockEvmCoinConfig = (
|
|
|
88
88
|
/**
|
|
89
89
|
* Builds a mock {@link EvmContext} for tests.
|
|
90
90
|
*
|
|
91
|
-
* The logic layer resolves its configuration through `context.config(
|
|
91
|
+
* The logic layer resolves its configuration through `context.config()`, so this
|
|
92
92
|
* accessor is the single source of config for the delegated calls. Pass an optional `config`
|
|
93
93
|
* to override what `context.config()` resolves to (merged over an `active` status default).
|
|
94
|
-
* The `currencyId` argument is accepted for signature parity but ignored — the mock always
|
|
95
|
-
* resolves the same config regardless of currency.
|
|
96
94
|
*/
|
|
97
95
|
export const createMockEvmContext = (config?: Partial<EvmConfigInfo>): EvmContext => ({
|
|
98
|
-
config: async (
|
|
96
|
+
config: async (): Promise<EvmConfigInfo> =>
|
|
99
97
|
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode(), ...config }),
|
|
100
98
|
logger: jest.fn(),
|
|
101
99
|
})
|
package/src/logic/broadcast.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { getNodeApi } from '../network/node/index'
|
|
|
7
7
|
|
|
8
8
|
export async function broadcast(
|
|
9
9
|
context: EvmContext,
|
|
10
|
-
currencyId: string,
|
|
11
10
|
{
|
|
12
11
|
signature,
|
|
13
12
|
broadcastConfig,
|
|
@@ -16,7 +15,7 @@ export async function broadcast(
|
|
|
16
15
|
broadcastConfig?: BroadcastConfig | undefined
|
|
17
16
|
}
|
|
18
17
|
): Promise<string> {
|
|
19
|
-
const config = await context.config(
|
|
18
|
+
const config = await context.config()
|
|
20
19
|
const nodeApi = getNodeApi(config, context.logger)
|
|
21
20
|
return await nodeApi.broadcastTransaction(signature, broadcastConfig)
|
|
22
21
|
}
|
|
@@ -20,7 +20,6 @@ import { isFeesStrategy } from './predicates'
|
|
|
20
20
|
|
|
21
21
|
export async function craftTransaction(
|
|
22
22
|
context: EvmContext,
|
|
23
|
-
currencyId: string,
|
|
24
23
|
{
|
|
25
24
|
transactionIntent,
|
|
26
25
|
customFees,
|
|
@@ -29,7 +28,7 @@ export async function craftTransaction(
|
|
|
29
28
|
customFees?: FeeEstimation | undefined
|
|
30
29
|
}
|
|
31
30
|
): Promise<CraftedTransaction> {
|
|
32
|
-
const config = await context.config(
|
|
31
|
+
const config = await context.config()
|
|
33
32
|
const { type, to, data, value, gasLimit } = await prepareUnsignedTxParams(
|
|
34
33
|
config,
|
|
35
34
|
transactionIntent,
|
|
@@ -48,7 +47,7 @@ export async function craftTransaction(
|
|
|
48
47
|
const nonce =
|
|
49
48
|
typeof transactionIntent.sequence === 'bigint' && transactionIntent.sequence >= 0n
|
|
50
49
|
? transactionIntent.sequence
|
|
51
|
-
: await getNextSequence(context,
|
|
50
|
+
: await getNextSequence(context, transactionIntent.sender)
|
|
52
51
|
const chainId = config.chainId
|
|
53
52
|
|
|
54
53
|
const unsignedTransaction: TransactionLike = {
|
|
@@ -14,6 +14,7 @@ import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
|
14
14
|
import type { TransactionLike } from 'ethers'
|
|
15
15
|
import BigNumber from 'bignumber.js'
|
|
16
16
|
import { Transaction } from 'ethers'
|
|
17
|
+
import { L1DataFeeUnavailableError } from '../errors'
|
|
17
18
|
import { getAdditionalLayer2Fees } from '../logic'
|
|
18
19
|
import { isEthAddress, isStakingIntent } from '../logic-public'
|
|
19
20
|
import { getGasTracker } from '../network/gasTracker'
|
|
@@ -24,6 +25,12 @@ import { getTransactionType, prepareUnsignedTxParams } from './common'
|
|
|
24
25
|
import { getNextSequence } from './getNextSequence'
|
|
25
26
|
import { isFeesStrategy } from './predicates'
|
|
26
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Multiplier applied to the L1 data fee (`additionalFees`) of a send-max estimate only.
|
|
30
|
+
* The L1 fee follows the L1 base fee, which can rise between estimate and broadcast; for a
|
|
31
|
+
* send-max the amount is balance minus fees, so an under-estimate would make the transaction fail.
|
|
32
|
+
* Other estimates return the raw oracle value.
|
|
33
|
+
*/
|
|
27
34
|
const SEND_MAX_L1_FEE_BUFFER = new BigNumber(2)
|
|
28
35
|
|
|
29
36
|
async function computeAdditionalFees(
|
|
@@ -41,11 +48,23 @@ async function computeAdditionalFees(
|
|
|
41
48
|
},
|
|
42
49
|
}
|
|
43
50
|
|
|
51
|
+
let serialized: string
|
|
44
52
|
try {
|
|
45
|
-
|
|
53
|
+
serialized = Transaction.from(transaction).serialized
|
|
46
54
|
} catch {
|
|
47
55
|
return new BigNumber(0)
|
|
48
56
|
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
return await getAdditionalLayer2Fees(config, serialized, logger)
|
|
60
|
+
} catch (error) {
|
|
61
|
+
const reason = error instanceof Error ? error.message : String(error)
|
|
62
|
+
throw new L1DataFeeUnavailableError(
|
|
63
|
+
`Could not get the L1 data fee for chain ${config.name}: ${reason}`,
|
|
64
|
+
{ chainId: config.chainId },
|
|
65
|
+
{ cause: error }
|
|
66
|
+
)
|
|
67
|
+
}
|
|
49
68
|
}
|
|
50
69
|
|
|
51
70
|
function toApiFeeData(feeData: FeeData): ApiFeeData {
|
|
@@ -117,7 +136,6 @@ function extractGasOptions(
|
|
|
117
136
|
|
|
118
137
|
export async function estimateFees(
|
|
119
138
|
context: EvmContext,
|
|
120
|
-
currencyId: string,
|
|
121
139
|
transactionIntent: TransactionIntent<MemoNotSupported, BufferTxData>,
|
|
122
140
|
customFeesParameters?: FeeEstimation['parameters']
|
|
123
141
|
): Promise<FeeEstimation> {
|
|
@@ -125,7 +143,7 @@ export async function estimateFees(
|
|
|
125
143
|
return { value: 0n }
|
|
126
144
|
}
|
|
127
145
|
|
|
128
|
-
const config = await context.config(
|
|
146
|
+
const config = await context.config()
|
|
129
147
|
|
|
130
148
|
// Skip fee estimation for redelegate without a destination validator — the
|
|
131
149
|
// validateStaking step in validateIntent will surface RedelegateDstValAddressRequired.
|
|
@@ -147,7 +165,7 @@ export async function estimateFees(
|
|
|
147
165
|
const noncePromise: Promise<bigint> =
|
|
148
166
|
typeof transactionIntent.sequence === 'bigint' && transactionIntent.sequence >= 0n
|
|
149
167
|
? Promise.resolve(transactionIntent.sequence)
|
|
150
|
-
: getNextSequence(context,
|
|
168
|
+
: getNextSequence(context, transactionIntent.sender)
|
|
151
169
|
|
|
152
170
|
const feeDataPromise = (async (): Promise<{
|
|
153
171
|
finalFeeData: FeeData
|
package/src/logic/getBalance.ts
CHANGED
|
@@ -16,23 +16,21 @@ export const TOKEN_BALANCE_BATCH_SIZE = 8
|
|
|
16
16
|
/**
|
|
17
17
|
* Get all assets linked to the user (native, tokens, ...)
|
|
18
18
|
* @param context - The coin-module context (config + logger)
|
|
19
|
-
* @param currencyId - The currency id we must get the balances of
|
|
20
19
|
* @param address - The user's address
|
|
21
20
|
* @returns Promise<Balance[]> - Array of balances for all assets (first element will always be the native asset)
|
|
22
21
|
*/
|
|
23
22
|
export async function getBalance(
|
|
24
23
|
context: EvmContext,
|
|
25
|
-
currencyId: string,
|
|
26
24
|
address: string,
|
|
27
25
|
options?: BalanceOptions
|
|
28
26
|
): Promise<Balance[]> {
|
|
29
|
-
const config = await context.config(
|
|
27
|
+
const config = await context.config()
|
|
30
28
|
const nodeApi = getNodeApi(config, context.logger)
|
|
31
29
|
const explorerApi = getExplorerApi(config)
|
|
32
30
|
|
|
33
31
|
const [nativeBalance, tokensBalances] = await Promise.all([
|
|
34
32
|
getNativeBalance(address, nodeApi),
|
|
35
|
-
getTokenBalances(context,
|
|
33
|
+
getTokenBalances(context, address, nodeApi, explorerApi, config, options),
|
|
36
34
|
])
|
|
37
35
|
|
|
38
36
|
return [nativeBalance].concat(tokensBalances)
|
|
@@ -50,7 +48,6 @@ async function getNativeBalance(address: string, nodeApi: NodeApi): Promise<Bala
|
|
|
50
48
|
|
|
51
49
|
async function getTokenBalances(
|
|
52
50
|
context: EvmContext,
|
|
53
|
-
currencyId: string,
|
|
54
51
|
address: string,
|
|
55
52
|
nodeApi: NodeApi,
|
|
56
53
|
explorerApi: ExplorerApi,
|
|
@@ -124,7 +121,7 @@ async function getTokenBalances(
|
|
|
124
121
|
// Staking and token-asset collection run in parallel; staking depends on the coin operations
|
|
125
122
|
// fetched above (Monad only), token-asset collection on the discovered/known assets union.
|
|
126
123
|
const [stakingResult, tokenAssetsResult] = await Promise.allSettled([
|
|
127
|
-
getStakes(context,
|
|
124
|
+
getStakes(context, address, { knownValidatorIds }),
|
|
128
125
|
collectTokenAssets(
|
|
129
126
|
Array.from(knownAssetsByReference.values()),
|
|
130
127
|
address,
|
package/src/logic/getBlock.ts
CHANGED
|
@@ -21,11 +21,7 @@ import { getNodeApi } from '../network/node'
|
|
|
21
21
|
import { createInternalTransactionsFetcher } from './internalTransactionsFetcher'
|
|
22
22
|
import { dropRootTraceDuplicates } from './rootTraceDedup'
|
|
23
23
|
|
|
24
|
-
export async function getBlock(
|
|
25
|
-
context: EvmContext,
|
|
26
|
-
currencyId: string,
|
|
27
|
-
height: number
|
|
28
|
-
): Promise<Block> {
|
|
24
|
+
export async function getBlock(context: EvmContext, height: number): Promise<Block> {
|
|
29
25
|
// Note: to use RPC calls efficiently, the strategy here is:
|
|
30
26
|
// - fetch the block + transactions in one call (using prefetchTxs=true)
|
|
31
27
|
// - fetch transaction receipts in one call using eth_getBlockReceipts
|
|
@@ -34,7 +30,7 @@ export async function getBlock(
|
|
|
34
30
|
// - unless the block is empty, fetch internal transactions (RPC trace methods or explorer,
|
|
35
31
|
// per `getBlockInternalTxsSources`) in parallel with the receipts, and merge them into the
|
|
36
32
|
// block transactions
|
|
37
|
-
const config = await context.config(
|
|
33
|
+
const config = await context.config()
|
|
38
34
|
const nodeApi = getNodeApi(config, context.logger)
|
|
39
35
|
const internalTxSources = config.getBlockInternalTxsSources ?? DEFAULT_INTERNAL_TX_SOURCES
|
|
40
36
|
const fetchInternalTxs = createInternalTransactionsFetcher(
|
|
@@ -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 {
|
|
@@ -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
|
})
|
|
@@ -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
|
})
|
|
@@ -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,
|
|
@@ -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',
|