@ledgerhq/coin-evm 5.3.1 → 5.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.oxlintrc.json +3 -13
- package/CHANGELOG.md +13 -0
- package/lib/adapters/blockOperations.d.ts +2 -2
- package/lib/adapters/blockOperations.d.ts.map +1 -1
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/logic/combine.d.ts +2 -1
- package/lib/logic/combine.d.ts.map +1 -1
- package/lib/logic/combine.js.map +1 -1
- package/lib/logic/common.d.ts +2 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransactionData.d.ts +1 -1
- package/lib/logic/craftTransactionData.d.ts.map +1 -1
- package/lib/logic/estimateFees.d.ts +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getStakes.d.ts +1 -1
- package/lib/logic/getStakes.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/validateIntent.d.ts +1 -1
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic.d.ts +1 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +4 -4
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/index.d.ts +2 -2
- package/lib/network/explorer/index.d.ts.map +1 -1
- package/lib/network/explorer/index.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts +2 -2
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/none.d.ts +1 -1
- package/lib/network/explorer/none.d.ts.map +1 -1
- package/lib/network/explorer/none.js.map +1 -1
- package/lib/network/explorer/types.d.ts +1 -1
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/gasTracker/index.d.ts +2 -2
- package/lib/network/gasTracker/index.d.ts.map +1 -1
- package/lib/network/gasTracker/index.js.map +1 -1
- package/lib/network/gasTracker/ledger.d.ts +3 -3
- package/lib/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib/network/gasTracker/ledger.js.map +1 -1
- package/lib/network/gasTracker/types.d.ts +2 -2
- package/lib/network/gasTracker/types.d.ts.map +1 -1
- package/lib/network/node/ledger.d.ts +2 -2
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +3 -3
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/staking/validators/monad.d.ts +2 -1
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/monadResolver.d.ts +2 -1
- package/lib/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib/staking/validators/somnia.d.ts.map +1 -1
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib/types/assets.d.ts +1 -1
- package/lib/types/assets.d.ts.map +1 -1
- package/lib/types/transaction.d.ts +1 -1
- package/lib/types/transaction.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.d.ts +2 -2
- package/lib-es/adapters/blockOperations.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/api/index.d.ts +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/config.d.ts +1 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/logic/combine.d.ts +2 -1
- package/lib-es/logic/combine.d.ts.map +1 -1
- package/lib-es/logic/combine.js.map +1 -1
- package/lib-es/logic/common.d.ts +2 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +1 -1
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransactionData.d.ts +1 -1
- package/lib-es/logic/craftTransactionData.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getStakes.d.ts +1 -1
- package/lib-es/logic/getStakes.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts +1 -1
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic.d.ts +1 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +4 -4
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/index.d.ts +2 -2
- package/lib-es/network/explorer/index.d.ts.map +1 -1
- package/lib-es/network/explorer/index.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts +2 -2
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/none.d.ts +1 -1
- package/lib-es/network/explorer/none.d.ts.map +1 -1
- package/lib-es/network/explorer/none.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +1 -1
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.d.ts +2 -2
- package/lib-es/network/gasTracker/index.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.js.map +1 -1
- package/lib-es/network/gasTracker/ledger.d.ts +3 -3
- package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib-es/network/gasTracker/ledger.js +1 -1
- package/lib-es/network/gasTracker/ledger.js.map +1 -1
- package/lib-es/network/gasTracker/types.d.ts +2 -2
- package/lib-es/network/gasTracker/types.d.ts.map +1 -1
- package/lib-es/network/node/ledger.d.ts +2 -2
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +1 -1
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +3 -3
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.d.ts +2 -1
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.d.ts +2 -1
- package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/staking/validators/somnia.d.ts.map +1 -1
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/types/assets.d.ts +1 -1
- package/lib-es/types/assets.d.ts.map +1 -1
- package/lib-es/types/transaction.d.ts +1 -1
- package/lib-es/types/transaction.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/adapters/blockOperations.test.ts +29 -31
- package/src/adapters/blockOperations.ts +3 -2
- package/src/adapters/etherscan.test.ts +7 -7
- package/src/adapters/ledger.test.ts +2 -2
- package/src/api/getBlock.integ.test.ts +1 -1
- package/src/api/index.fantom.integ.test.ts +1 -1
- package/src/api/index.flare.integ.test.ts +2 -14
- package/src/api/index.integ.test.ts +330 -246
- package/src/api/index.linea.integ.test.ts +1 -1
- package/src/api/index.optimism.integ.test.ts +1 -1
- package/src/api/index.shape.integ.test.ts +1 -1
- package/src/api/index.ts +1 -1
- package/src/config.ts +1 -1
- package/src/fixtures/context.fixtures.ts +79 -1
- package/src/fixtures/ethers.fixtures.ts +26 -0
- package/src/fixtures/ledger.fixtures.ts +1 -1
- package/src/internalTxSources.test.ts +3 -6
- package/src/logic/broadcast.integ.test.ts +6 -18
- package/src/logic/broadcast.test.ts +19 -31
- package/src/logic/broadcastSource.test.ts +6 -7
- package/src/logic/combine.test.ts +2 -2
- package/src/logic/combine.ts +2 -1
- package/src/logic/common.test.ts +120 -112
- package/src/logic/common.ts +2 -7
- package/src/logic/craftTransaction.test.ts +163 -200
- package/src/logic/craftTransaction.ts +3 -2
- package/src/logic/craftTransactionData.test.ts +6 -6
- package/src/logic/craftTransactionData.ts +1 -1
- package/src/logic/estimateFees.test.ts +19 -15
- package/src/logic/estimateFees.ts +6 -3
- package/src/logic/getBalance.test.ts +16 -15
- package/src/logic/getBalance.ts +4 -3
- package/src/logic/getBlock.test.ts +379 -388
- package/src/logic/getBlock.ts +3 -2
- package/src/logic/getBlockInfo.test.ts +7 -9
- package/src/logic/getNextSequence.test.ts +5 -5
- package/src/logic/getStakes.test.ts +35 -35
- package/src/logic/getStakes.ts +1 -1
- package/src/logic/internalTransactionsFetcher.test.ts +26 -24
- package/src/logic/internalTransactionsFetcher.ts +1 -1
- package/src/logic/lastBlock.test.ts +29 -20
- package/src/logic/listOperations.test.ts +44 -40
- package/src/logic/validateIntent.test.ts +152 -101
- package/src/logic/validateIntent.ts +4 -2
- package/src/logic.test.ts +13 -18
- package/src/logic.ts +1 -1
- package/src/network/explorer/etherscan.test.ts +6 -6
- package/src/network/explorer/etherscan.ts +12 -10
- package/src/network/explorer/index.test.ts +52 -22
- package/src/network/explorer/index.ts +2 -2
- package/src/network/explorer/ledger.test.ts +17 -5
- package/src/network/explorer/ledger.ts +3 -2
- package/src/network/explorer/none.ts +2 -1
- package/src/network/explorer/types.ts +1 -1
- package/src/network/gasTracker/index.test.ts +14 -8
- package/src/network/gasTracker/index.ts +2 -2
- package/src/network/gasTracker/ledger.test.ts +34 -29
- package/src/network/gasTracker/ledger.ts +5 -7
- package/src/network/gasTracker/types.ts +2 -2
- package/src/network/node/index.memoization.test.ts +25 -31
- package/src/network/node/index.test.ts +14 -25
- package/src/network/node/ledger.test.ts +45 -60
- package/src/network/node/ledger.ts +6 -5
- package/src/network/node/node.fixtures.ts +0 -2
- package/src/network/node/rpc.common.ts +14 -14
- package/src/network/node/rpc.test.ts +153 -184
- package/src/network/node/types.ts +3 -3
- package/src/staking/detectOperationType.test.ts +1 -1
- package/src/staking/encoder.test.ts +14 -22
- package/src/staking/logic.test.ts +20 -14
- package/src/staking/operations/index.test.ts +29 -29
- package/src/staking/prepareIntents.test.ts +26 -20
- package/src/staking/redelegations.test.ts +50 -33
- package/src/staking/rewards.test.ts +29 -17
- package/src/staking/rewardsFromReceipt.test.ts +20 -21
- package/src/staking/transactionData.test.ts +23 -23
- package/src/staking/validators/monad.test.ts +65 -24
- package/src/staking/validators/monad.ts +2 -1
- package/src/staking/validators/monadResolver.ts +2 -1
- package/src/staking/validators/somnia.test.ts +21 -13
- package/src/staking/validators/somnia.ts +2 -1
- package/src/staking/validators/zero_gravity.test.ts +118 -48
- package/src/staking/validators/zero_gravity.ts +2 -1
- package/src/staking/validators.integ.test.ts +13 -25
- package/src/staking/validators.test.ts +7 -2
- package/src/types/assets.ts +1 -1
- package/src/types/transaction.ts +1 -1
|
@@ -1,46 +1,42 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
BufferTxData,
|
|
6
|
-
FeeEstimation,
|
|
7
|
-
MemoNotSupported,
|
|
8
|
-
Operation,
|
|
9
|
-
StakingTransactionIntent,
|
|
10
|
-
} from '@ledgerhq/coin-module-framework/api/types'
|
|
4
|
+
import type { Operation } from '@ledgerhq/coin-module-framework/api/types'
|
|
11
5
|
import { ethers } from 'ethers'
|
|
12
|
-
import {
|
|
13
|
-
|
|
6
|
+
import {
|
|
7
|
+
createMockEvmConfigInfo,
|
|
8
|
+
createMockEvmContext,
|
|
9
|
+
mkEtherscanExplorer,
|
|
10
|
+
mkExternalNode,
|
|
11
|
+
mkLedgerExplorer,
|
|
12
|
+
mkLedgerNode,
|
|
13
|
+
} from '../fixtures/context.fixtures'
|
|
14
14
|
import { createApi } from './index'
|
|
15
15
|
|
|
16
16
|
describe.each([
|
|
17
17
|
[
|
|
18
18
|
'external node and explorer',
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/1',
|
|
24
|
-
},
|
|
19
|
+
createMockEvmConfigInfo({
|
|
20
|
+
chainId: 1,
|
|
21
|
+
node: mkExternalNode({ uri: 'https://ethereum-rpc.publicnode.com' }),
|
|
22
|
+
explorer: mkEtherscanExplorer({ uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/1' }),
|
|
25
23
|
supportedTokens: ['erc721', 'erc1155'],
|
|
26
|
-
},
|
|
24
|
+
}),
|
|
27
25
|
],
|
|
28
26
|
[
|
|
29
27
|
'ledger node and explorer',
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
explorerId: 'eth',
|
|
35
|
-
},
|
|
28
|
+
createMockEvmConfigInfo({
|
|
29
|
+
chainId: 1,
|
|
30
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
31
|
+
explorer: mkLedgerExplorer({ explorerId: 'eth' }),
|
|
36
32
|
supportedTokens: ['erc721', 'erc1155'],
|
|
37
|
-
},
|
|
33
|
+
}),
|
|
38
34
|
],
|
|
39
35
|
])('EVM Api (%s)', (_, config) => {
|
|
40
36
|
let module: ReturnType<typeof createApi>
|
|
41
37
|
// The logic layer resolves config from the threaded context (ADR-019), so the context must
|
|
42
38
|
// carry this suite's node/explorer config — not the empty default fixture.
|
|
43
|
-
const context = createMockEvmContext(config
|
|
39
|
+
const context = createMockEvmContext(config)
|
|
44
40
|
beforeAll(() => {
|
|
45
41
|
module = createApi('ethereum')
|
|
46
42
|
})
|
|
@@ -190,38 +186,38 @@ describe.each([
|
|
|
190
186
|
})
|
|
191
187
|
})
|
|
192
188
|
|
|
193
|
-
describe
|
|
194
|
-
|
|
195
|
-
'legacy',
|
|
196
|
-
(transaction: ethers.Transaction): void => {
|
|
197
|
-
expect(transaction.type).toBe(0)
|
|
198
|
-
expect(typeof transaction.gasPrice).toBe('bigint')
|
|
199
|
-
expect(transaction.gasPrice).toBeGreaterThan(0)
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
[
|
|
203
|
-
'eip1559',
|
|
204
|
-
(transaction: ethers.Transaction): void => {
|
|
205
|
-
expect(transaction.type).toBe(2)
|
|
206
|
-
expect(transaction.gasPrice).toBeNull()
|
|
207
|
-
expect(typeof transaction.maxFeePerGas).toBe('bigint')
|
|
208
|
-
expect(typeof transaction.maxPriorityFeePerGas).toBe('bigint')
|
|
209
|
-
expect(transaction.maxFeePerGas).toBeGreaterThan(0n)
|
|
210
|
-
expect(transaction.maxPriorityFeePerGas).toBeGreaterThan(0n)
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
])('craftTransaction', (mode, expectTransactionForMode) => {
|
|
214
|
-
it('crafts a transaction with the native asset', async () => {
|
|
189
|
+
describe('craftTransaction', () => {
|
|
190
|
+
it('crafts a legacy transaction with the native asset', async () => {
|
|
215
191
|
const { transaction: result } = await module.craftTransaction(context, {
|
|
216
|
-
type:
|
|
192
|
+
type: 'send-legacy',
|
|
217
193
|
intentType: 'transaction',
|
|
218
194
|
amount: 10n,
|
|
219
195
|
sender: '0x9bcd841436ef4f85dacefb1aec772af71619024e',
|
|
220
196
|
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
221
197
|
data: { type: 'buffer', value: Buffer.from([]) },
|
|
222
|
-
asset: {
|
|
223
|
-
|
|
224
|
-
|
|
198
|
+
asset: { type: 'native' },
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
expect(result).toMatch(/^0x[A-Fa-f0-9]+$/)
|
|
202
|
+
expect(ethers.Transaction.from(result)).toMatchObject({
|
|
203
|
+
value: 10n,
|
|
204
|
+
to: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
|
|
205
|
+
})
|
|
206
|
+
const tx = ethers.Transaction.from(result)
|
|
207
|
+
expect(tx.type).toBe(0)
|
|
208
|
+
expect(typeof tx.gasPrice).toBe('bigint')
|
|
209
|
+
expect(tx.gasPrice).toBeGreaterThan(0)
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
it('crafts an eip1559 transaction with the native asset', async () => {
|
|
213
|
+
const { transaction: result } = await module.craftTransaction(context, {
|
|
214
|
+
type: 'send-eip1559',
|
|
215
|
+
intentType: 'transaction',
|
|
216
|
+
amount: 10n,
|
|
217
|
+
sender: '0x9bcd841436ef4f85dacefb1aec772af71619024e',
|
|
218
|
+
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
219
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
220
|
+
asset: { type: 'native' },
|
|
225
221
|
})
|
|
226
222
|
|
|
227
223
|
expect(result).toMatch(/^0x[A-Fa-f0-9]+$/)
|
|
@@ -229,14 +225,51 @@ describe.each([
|
|
|
229
225
|
value: 10n,
|
|
230
226
|
to: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
|
|
231
227
|
})
|
|
232
|
-
|
|
228
|
+
const tx = ethers.Transaction.from(result)
|
|
229
|
+
expect(tx.type).toBe(2)
|
|
230
|
+
expect(tx.gasPrice).toBeNull()
|
|
231
|
+
expect(typeof tx.maxFeePerGas).toBe('bigint')
|
|
232
|
+
expect(typeof tx.maxPriorityFeePerGas).toBe('bigint')
|
|
233
|
+
expect(tx.maxFeePerGas).toBeGreaterThan(0n)
|
|
234
|
+
expect(tx.maxPriorityFeePerGas).toBeGreaterThan(0n)
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
it('crafts a legacy transaction with the USDC asset', async () => {
|
|
238
|
+
const { transaction: result } = await module.craftTransaction(
|
|
239
|
+
context,
|
|
240
|
+
{
|
|
241
|
+
type: 'send-legacy',
|
|
242
|
+
intentType: 'transaction',
|
|
243
|
+
amount: 10n,
|
|
244
|
+
sender: '0x9bcd841436ef4f85dacefb1aec772af71619024e',
|
|
245
|
+
recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
|
|
246
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
247
|
+
asset: {
|
|
248
|
+
type: 'erc20',
|
|
249
|
+
assetReference: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
// The sender holds no USDC, so estimating this transfer reverts on-chain. Pin the gas
|
|
253
|
+
// limit so the test covers the crafted payload rather than a live token balance.
|
|
254
|
+
{ customFees: { value: 0n, parameters: { gasLimit: 60000n } } }
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
expect(result).toMatch(/^0x[A-Fa-f0-9]+$/)
|
|
258
|
+
expect(ethers.Transaction.from(result)).toMatchObject({
|
|
259
|
+
value: 0n,
|
|
260
|
+
to: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
261
|
+
})
|
|
262
|
+
const tx = ethers.Transaction.from(result)
|
|
263
|
+
expect(tx.type).toBe(0)
|
|
264
|
+
expect(typeof tx.gasPrice).toBe('bigint')
|
|
265
|
+
expect(tx.gasPrice).toBeGreaterThan(0)
|
|
233
266
|
})
|
|
234
267
|
|
|
235
|
-
it('crafts
|
|
268
|
+
it('crafts an eip1559 transaction with the USDC asset', async () => {
|
|
236
269
|
const { transaction: result } = await module.craftTransaction(
|
|
237
270
|
context,
|
|
238
271
|
{
|
|
239
|
-
type:
|
|
272
|
+
type: 'send-eip1559',
|
|
240
273
|
intentType: 'transaction',
|
|
241
274
|
amount: 10n,
|
|
242
275
|
sender: '0x9bcd841436ef4f85dacefb1aec772af71619024e',
|
|
@@ -257,7 +290,13 @@ describe.each([
|
|
|
257
290
|
value: 0n,
|
|
258
291
|
to: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
259
292
|
})
|
|
260
|
-
|
|
293
|
+
const tx = ethers.Transaction.from(result)
|
|
294
|
+
expect(tx.type).toBe(2)
|
|
295
|
+
expect(tx.gasPrice).toBeNull()
|
|
296
|
+
expect(typeof tx.maxFeePerGas).toBe('bigint')
|
|
297
|
+
expect(typeof tx.maxPriorityFeePerGas).toBe('bigint')
|
|
298
|
+
expect(tx.maxFeePerGas).toBeGreaterThan(0n)
|
|
299
|
+
expect(tx.maxPriorityFeePerGas).toBeGreaterThan(0n)
|
|
261
300
|
})
|
|
262
301
|
})
|
|
263
302
|
|
|
@@ -299,19 +338,14 @@ describe.each([
|
|
|
299
338
|
* "To send batches over 10 items, consider using a dedicated API provider"
|
|
300
339
|
*/
|
|
301
340
|
it('returns at least 10 token balances on Optimisim', async () => {
|
|
302
|
-
const config = {
|
|
303
|
-
node: {
|
|
304
|
-
type: 'external',
|
|
305
|
-
uri: 'https://mainnet.optimism.io',
|
|
306
|
-
},
|
|
307
|
-
explorer: {
|
|
308
|
-
type: 'blockscout',
|
|
309
|
-
uri: 'https://optimism.blockscout.com/api',
|
|
310
|
-
},
|
|
311
|
-
}
|
|
312
341
|
const module = createApi('optimism')
|
|
313
|
-
|
|
314
|
-
|
|
342
|
+
const context = createMockEvmContext(
|
|
343
|
+
createMockEvmConfigInfo({
|
|
344
|
+
chainId: 10,
|
|
345
|
+
node: mkExternalNode({ uri: 'https://mainnet.optimism.io' }),
|
|
346
|
+
explorer: { type: 'blockscout' as const, uri: 'https://optimism.blockscout.com/api' },
|
|
347
|
+
})
|
|
348
|
+
)
|
|
315
349
|
const result = await module.getBalance(context, '0x1CDDb825910426644e00e769072Ce1Ea7d4e34BB')
|
|
316
350
|
|
|
317
351
|
expect(result.length).toBeGreaterThan(10)
|
|
@@ -372,11 +406,11 @@ describe.each([
|
|
|
372
406
|
expect(op.tx.fees).toBeGreaterThanOrEqual(0n) // fees not available for all internal transactions
|
|
373
407
|
expect(op.tx.date).toBeInstanceOf(Date)
|
|
374
408
|
})
|
|
375
|
-
expect(isCorrectlyOrdered(result))
|
|
409
|
+
expect(isCorrectlyOrdered(result)).toBe(true)
|
|
376
410
|
}
|
|
377
411
|
)
|
|
378
412
|
|
|
379
|
-
const isEtherscanLike =
|
|
413
|
+
const isEtherscanLike = config.explorer?.type === 'etherscan'
|
|
380
414
|
|
|
381
415
|
describe('pagination', () => {
|
|
382
416
|
const expectUniqueOperationIds = (ops: Operation[]) => {
|
|
@@ -397,6 +431,7 @@ describe.each([
|
|
|
397
431
|
// TODO implement pagination for ledger explorer
|
|
398
432
|
// Pagination tests only make sense for etherscan-like explorers that support real pagination.
|
|
399
433
|
// Ledger explorer fetches all data in one call looping over all the pages and returns NO_TOKEN.
|
|
434
|
+
// oxlint-disable jest/no-standalone-expect -- ternary test runner not recognized by static analysis
|
|
400
435
|
;(isEtherscanLike ? it.each : it.skip.each)([
|
|
401
436
|
// note that the ASC mode is really slow
|
|
402
437
|
['ascending', 'asc'],
|
|
@@ -523,6 +558,7 @@ describe.each([
|
|
|
523
558
|
expect(hasOverlap).toBe(false)
|
|
524
559
|
}
|
|
525
560
|
})
|
|
561
|
+
// oxlint-enable jest/no-standalone-expect
|
|
526
562
|
})
|
|
527
563
|
|
|
528
564
|
describe('transactions non-regression', () => {
|
|
@@ -609,14 +645,13 @@ describe.each([
|
|
|
609
645
|
asset: { type: 'erc20' },
|
|
610
646
|
tx: { feesPayer: expect.any(String) },
|
|
611
647
|
})
|
|
612
|
-
const senderAsset = senderTxOps[0].asset
|
|
613
|
-
|
|
614
|
-
|
|
648
|
+
const senderAsset = senderTxOps[0].asset
|
|
649
|
+
if (senderAsset.type !== 'native') {
|
|
650
|
+
expect(senderAsset.assetReference?.toLowerCase()).toBe(contract.toLowerCase())
|
|
651
|
+
expectAddressEq(senderTxOps[0].senders[0], sender)
|
|
652
|
+
expectAddressEq(senderTxOps[0].recipients[0], recipient)
|
|
653
|
+
expectAddressEq(senderAsset.assetOwner, sender)
|
|
615
654
|
}
|
|
616
|
-
expect(senderAsset.assetReference?.toLowerCase()).toBe(contract.toLowerCase())
|
|
617
|
-
expectAddressEq(senderTxOps[0].senders[0], sender)
|
|
618
|
-
expectAddressEq(senderTxOps[0].recipients[0], recipient)
|
|
619
|
-
expectAddressEq(senderAsset.assetOwner!, sender)
|
|
620
655
|
expectAddressEq(senderTxOps[0].tx.feesPayer!, sender)
|
|
621
656
|
expect(senderTxOps[0].value).toBeGreaterThan(0n)
|
|
622
657
|
|
|
@@ -625,14 +660,13 @@ describe.each([
|
|
|
625
660
|
type: 'IN',
|
|
626
661
|
asset: { type: 'erc20' },
|
|
627
662
|
})
|
|
628
|
-
const recipientAsset = recipientTxOps[0].asset
|
|
629
|
-
|
|
630
|
-
|
|
663
|
+
const recipientAsset = recipientTxOps[0].asset
|
|
664
|
+
if (recipientAsset.type !== 'native') {
|
|
665
|
+
expect(recipientAsset.assetReference?.toLowerCase()).toBe(contract.toLowerCase())
|
|
666
|
+
expectAddressEq(recipientTxOps[0].senders[0], sender)
|
|
667
|
+
expectAddressEq(recipientTxOps[0].recipients[0], recipient)
|
|
668
|
+
expectAddressEq(recipientAsset.assetOwner, recipient)
|
|
631
669
|
}
|
|
632
|
-
expect(recipientAsset.assetReference?.toLowerCase()).toBe(contract.toLowerCase())
|
|
633
|
-
expectAddressEq(recipientTxOps[0].senders[0], sender)
|
|
634
|
-
expectAddressEq(recipientTxOps[0].recipients[0], recipient)
|
|
635
|
-
expectAddressEq(recipientAsset.assetOwner!, recipient)
|
|
636
670
|
expect(recipientTxOps[0].value).toBe(senderTxOps[0].value)
|
|
637
671
|
})
|
|
638
672
|
|
|
@@ -673,9 +707,11 @@ describe.each([
|
|
|
673
707
|
asset: { type: 'erc20', assetOwner: expect.any(String) },
|
|
674
708
|
tx: { feesPayer: expect.any(String) },
|
|
675
709
|
})
|
|
676
|
-
const tokenOpAsset = tokenOp!.asset
|
|
677
|
-
|
|
678
|
-
|
|
710
|
+
const tokenOpAsset = tokenOp!.asset
|
|
711
|
+
if (tokenOpAsset.type !== 'native') {
|
|
712
|
+
expect(tokenOpAsset.assetReference?.toLowerCase()).toBe(lidoContract.toLowerCase())
|
|
713
|
+
expectAddressEq(tokenOpAsset.assetOwner, sender)
|
|
714
|
+
}
|
|
679
715
|
expect(tokenOp!.senders[0].toLowerCase()).toBe(zeroAddress.toLowerCase())
|
|
680
716
|
expectAddressEq(tokenOp!.recipients[0], sender)
|
|
681
717
|
expectAddressEq(tokenOp!.tx.feesPayer!, sender)
|
|
@@ -715,65 +751,93 @@ describe.each([
|
|
|
715
751
|
})
|
|
716
752
|
})
|
|
717
753
|
|
|
718
|
-
describe
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
maxPriorityFeePerGas: expect.any(BigInt),
|
|
747
|
-
nextBaseFee: expect.any(BigInt),
|
|
748
|
-
type: 2,
|
|
749
|
-
},
|
|
750
|
-
})
|
|
751
|
-
expect(estimation.value).toBeGreaterThan(0)
|
|
752
|
-
expect(estimation.parameters?.maxFeePerGas).toBeGreaterThan(0)
|
|
753
|
-
expect(estimation.parameters?.maxPriorityFeePerGas).toBeGreaterThan(0)
|
|
754
|
-
expect(estimation.parameters?.nextBaseFee).toBeGreaterThan(0)
|
|
755
|
-
},
|
|
756
|
-
],
|
|
757
|
-
])('estimateFees for %s transaction', (mode, expectEstimationForMode) => {
|
|
758
|
-
it('estimates fees for native asset transfer', async () => {
|
|
754
|
+
describe('estimateFees', () => {
|
|
755
|
+
it('estimates fees for legacy native asset transfer', async () => {
|
|
756
|
+
const result = await module.estimateFees(context, {
|
|
757
|
+
type: 'send-legacy',
|
|
758
|
+
intentType: 'transaction',
|
|
759
|
+
amount: 100000000000000n, // 0.0001 ETH (smaller amount)
|
|
760
|
+
sender: '0xDb3812cD8d20F27888677dDC97dF1241850f8c48',
|
|
761
|
+
recipient: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
|
|
762
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
763
|
+
asset: { type: 'native' },
|
|
764
|
+
})
|
|
765
|
+
|
|
766
|
+
expect(result).toEqual({
|
|
767
|
+
value: expect.any(BigInt),
|
|
768
|
+
parameters: {
|
|
769
|
+
gasPrice: expect.any(BigInt),
|
|
770
|
+
gasLimit: expect.any(BigInt),
|
|
771
|
+
maxFeePerGas: null,
|
|
772
|
+
maxPriorityFeePerGas: null,
|
|
773
|
+
nextBaseFee: null,
|
|
774
|
+
type: 0,
|
|
775
|
+
},
|
|
776
|
+
})
|
|
777
|
+
expect(result.value).toBeGreaterThan(0)
|
|
778
|
+
expect(result.parameters?.gasPrice).toBeGreaterThan(0)
|
|
779
|
+
})
|
|
780
|
+
|
|
781
|
+
it('estimates fees for eip1559 native asset transfer', async () => {
|
|
759
782
|
const result = await module.estimateFees(context, {
|
|
760
|
-
type:
|
|
783
|
+
type: 'send-eip1559',
|
|
761
784
|
intentType: 'transaction',
|
|
762
785
|
amount: 100000000000000n, // 0.0001 ETH (smaller amount)
|
|
763
786
|
sender: '0xDb3812cD8d20F27888677dDC97dF1241850f8c48',
|
|
764
787
|
recipient: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
|
|
765
788
|
data: { type: 'buffer', value: Buffer.from([]) },
|
|
789
|
+
asset: { type: 'native' },
|
|
790
|
+
})
|
|
791
|
+
|
|
792
|
+
expect(result).toEqual({
|
|
793
|
+
value: expect.any(BigInt),
|
|
794
|
+
parameters: {
|
|
795
|
+
gasPrice: null,
|
|
796
|
+
gasLimit: expect.any(BigInt),
|
|
797
|
+
maxFeePerGas: expect.any(BigInt),
|
|
798
|
+
maxPriorityFeePerGas: expect.any(BigInt),
|
|
799
|
+
nextBaseFee: expect.any(BigInt),
|
|
800
|
+
type: 2,
|
|
801
|
+
},
|
|
802
|
+
})
|
|
803
|
+
expect(result.value).toBeGreaterThan(0)
|
|
804
|
+
expect(result.parameters?.maxFeePerGas).toBeGreaterThan(0)
|
|
805
|
+
expect(result.parameters?.maxPriorityFeePerGas).toBeGreaterThan(0)
|
|
806
|
+
expect(result.parameters?.nextBaseFee).toBeGreaterThan(0)
|
|
807
|
+
})
|
|
808
|
+
|
|
809
|
+
it('estimates fees for legacy USDC token transfer', async () => {
|
|
810
|
+
const result = await module.estimateFees(context, {
|
|
811
|
+
type: 'send-legacy',
|
|
812
|
+
intentType: 'transaction',
|
|
813
|
+
amount: 1000000n, // 1 USDC (6 decimals)
|
|
814
|
+
sender: '0xDb3812cD8d20F27888677dDC97dF1241850f8c48',
|
|
815
|
+
recipient: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
|
|
816
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
766
817
|
asset: {
|
|
767
|
-
type: '
|
|
818
|
+
type: 'erc20',
|
|
819
|
+
assetReference: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
768
820
|
},
|
|
769
821
|
})
|
|
770
822
|
|
|
771
|
-
|
|
823
|
+
expect(result).toEqual({
|
|
824
|
+
value: expect.any(BigInt),
|
|
825
|
+
parameters: {
|
|
826
|
+
gasPrice: expect.any(BigInt),
|
|
827
|
+
gasLimit: expect.any(BigInt),
|
|
828
|
+
maxFeePerGas: null,
|
|
829
|
+
maxPriorityFeePerGas: null,
|
|
830
|
+
nextBaseFee: null,
|
|
831
|
+
type: 0,
|
|
832
|
+
},
|
|
833
|
+
})
|
|
834
|
+
expect(result.value).toBeGreaterThan(0)
|
|
835
|
+
expect(result.parameters?.gasPrice).toBeGreaterThan(0)
|
|
772
836
|
})
|
|
773
837
|
|
|
774
|
-
it('estimates fees for USDC token transfer', async () => {
|
|
838
|
+
it('estimates fees for eip1559 USDC token transfer', async () => {
|
|
775
839
|
const result = await module.estimateFees(context, {
|
|
776
|
-
type:
|
|
840
|
+
type: 'send-eip1559',
|
|
777
841
|
intentType: 'transaction',
|
|
778
842
|
amount: 1000000n, // 1 USDC (6 decimals)
|
|
779
843
|
sender: '0xDb3812cD8d20F27888677dDC97dF1241850f8c48',
|
|
@@ -785,22 +849,35 @@ describe.each([
|
|
|
785
849
|
},
|
|
786
850
|
})
|
|
787
851
|
|
|
788
|
-
|
|
852
|
+
expect(result).toEqual({
|
|
853
|
+
value: expect.any(BigInt),
|
|
854
|
+
parameters: {
|
|
855
|
+
gasPrice: null,
|
|
856
|
+
gasLimit: expect.any(BigInt),
|
|
857
|
+
maxFeePerGas: expect.any(BigInt),
|
|
858
|
+
maxPriorityFeePerGas: expect.any(BigInt),
|
|
859
|
+
nextBaseFee: expect.any(BigInt),
|
|
860
|
+
type: 2,
|
|
861
|
+
},
|
|
862
|
+
})
|
|
863
|
+
expect(result.value).toBeGreaterThan(0)
|
|
864
|
+
expect(result.parameters?.maxFeePerGas).toBeGreaterThan(0)
|
|
865
|
+
expect(result.parameters?.maxPriorityFeePerGas).toBeGreaterThan(0)
|
|
866
|
+
expect(result.parameters?.nextBaseFee).toBeGreaterThan(0)
|
|
789
867
|
})
|
|
790
868
|
})
|
|
791
869
|
})
|
|
792
870
|
|
|
793
871
|
describe('EVM Api: external node and explorer ONLY', () => {
|
|
794
872
|
let module: ReturnType<typeof createApi>
|
|
795
|
-
const
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/1',
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
const context = createMockEvmContext(config)
|
|
873
|
+
const context = createMockEvmContext(
|
|
874
|
+
createMockEvmConfigInfo({
|
|
875
|
+
chainId: 1,
|
|
876
|
+
node: mkExternalNode({ uri: 'https://ethereum-rpc.publicnode.com' }),
|
|
877
|
+
explorer: mkEtherscanExplorer({ uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/1' }),
|
|
878
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
879
|
+
})
|
|
880
|
+
)
|
|
804
881
|
|
|
805
882
|
beforeAll(() => {
|
|
806
883
|
module = createApi('ethereum')
|
|
@@ -881,14 +958,15 @@ describe('EVM Api: external node and explorer ONLY', () => {
|
|
|
881
958
|
|
|
882
959
|
describe('EVM Api (Moonbeam Network)', () => {
|
|
883
960
|
let module: ReturnType<typeof createApi>
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
961
|
+
const context = createMockEvmContext(
|
|
962
|
+
createMockEvmConfigInfo({
|
|
963
|
+
chainId: 1284,
|
|
964
|
+
node: mkExternalNode({ uri: 'https://rpc.api.moonbeam.network' }),
|
|
965
|
+
explorer: mkEtherscanExplorer({
|
|
966
|
+
uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/1284',
|
|
967
|
+
}),
|
|
968
|
+
})
|
|
969
|
+
)
|
|
892
970
|
|
|
893
971
|
beforeAll(() => {
|
|
894
972
|
module = createApi('moonbeam')
|
|
@@ -930,46 +1008,24 @@ describe('EVM Api (SEI Network)', () => {
|
|
|
930
1008
|
const seiStakingSender = '0x66c4371aE8FFeD2ec1c2EBbbcCfb7E494181E1E3'
|
|
931
1009
|
const seiStakingRecipient = '0x0000000000000000000000000000000000001005'
|
|
932
1010
|
const seiStakingDelegationAmount = 1000000000000000n // 0.001 SEI
|
|
933
|
-
const
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
uri: 'https://sei-evm-rpc.publicnode.com',
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
} as EvmConfig
|
|
943
|
-
const context = createMockEvmContext(config)
|
|
1011
|
+
const context = createMockEvmContext(
|
|
1012
|
+
createMockEvmConfigInfo({
|
|
1013
|
+
chainId: 1329,
|
|
1014
|
+
node: mkExternalNode({ uri: 'https://sei-evm-rpc.publicnode.com' }),
|
|
1015
|
+
explorer: mkEtherscanExplorer({
|
|
1016
|
+
uri: 'https://proxyetherscan.api.live.ledger.com/v2/api/1329',
|
|
1017
|
+
}),
|
|
1018
|
+
})
|
|
1019
|
+
)
|
|
944
1020
|
|
|
945
1021
|
beforeAll(() => {
|
|
946
1022
|
module = createApi('sei_evm')
|
|
947
1023
|
})
|
|
948
1024
|
|
|
949
|
-
describe
|
|
950
|
-
|
|
951
|
-
'legacy',
|
|
952
|
-
(transaction: ethers.Transaction): void => {
|
|
953
|
-
expect(transaction.type).toBe(0)
|
|
954
|
-
expect(typeof transaction.gasPrice).toBe('bigint')
|
|
955
|
-
expect(transaction.gasPrice).toBeGreaterThan(0)
|
|
956
|
-
},
|
|
957
|
-
],
|
|
958
|
-
[
|
|
959
|
-
'eip1559',
|
|
960
|
-
(transaction: ethers.Transaction): void => {
|
|
961
|
-
expect(transaction.type).toBe(2)
|
|
962
|
-
expect(transaction.gasPrice).toBeNull()
|
|
963
|
-
expect(typeof transaction.maxFeePerGas).toBe('bigint')
|
|
964
|
-
expect(typeof transaction.maxPriorityFeePerGas).toBe('bigint')
|
|
965
|
-
expect(transaction.maxFeePerGas).toBeGreaterThan(0n)
|
|
966
|
-
expect(transaction.maxPriorityFeePerGas).toBeGreaterThan(0n)
|
|
967
|
-
},
|
|
968
|
-
],
|
|
969
|
-
])('craftTransaction', (mode, expectTransactionForMode) => {
|
|
970
|
-
it('crafts a delegate transaction', async () => {
|
|
1025
|
+
describe('craftTransaction', () => {
|
|
1026
|
+
it('crafts a legacy delegate transaction', async () => {
|
|
971
1027
|
const { transaction: result } = await module.craftTransaction(context, {
|
|
972
|
-
type:
|
|
1028
|
+
type: 'staking-legacy',
|
|
973
1029
|
intentType: 'staking' as const,
|
|
974
1030
|
amount: seiStakingDelegationAmount,
|
|
975
1031
|
mode: 'delegate',
|
|
@@ -977,63 +1033,52 @@ describe('EVM Api (SEI Network)', () => {
|
|
|
977
1033
|
recipient: seiStakingRecipient,
|
|
978
1034
|
valAddress: 'seivaloper1ummny4p645xraxc4m7nphf7vxawfzt3p5hn47t',
|
|
979
1035
|
data: { type: 'buffer', value: Buffer.from([]) },
|
|
980
|
-
asset: {
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1036
|
+
asset: { type: 'native' },
|
|
1037
|
+
})
|
|
1038
|
+
|
|
1039
|
+
expect(result).toMatch(/^0x[A-Fa-f0-9]+$/)
|
|
1040
|
+
expect(ethers.Transaction.from(result)).toMatchObject({
|
|
1041
|
+
value: seiStakingDelegationAmount,
|
|
1042
|
+
to: seiStakingRecipient,
|
|
1043
|
+
})
|
|
1044
|
+
const tx = ethers.Transaction.from(result)
|
|
1045
|
+
expect(tx.type).toBe(0)
|
|
1046
|
+
expect(typeof tx.gasPrice).toBe('bigint')
|
|
1047
|
+
expect(tx.gasPrice).toBeGreaterThan(0)
|
|
1048
|
+
})
|
|
1049
|
+
|
|
1050
|
+
it('crafts an eip1559 delegate transaction', async () => {
|
|
1051
|
+
const { transaction: result } = await module.craftTransaction(context, {
|
|
1052
|
+
type: 'staking-eip1559',
|
|
1053
|
+
intentType: 'staking' as const,
|
|
1054
|
+
amount: seiStakingDelegationAmount,
|
|
1055
|
+
mode: 'delegate',
|
|
1056
|
+
sender: seiStakingSender,
|
|
1057
|
+
recipient: seiStakingRecipient,
|
|
1058
|
+
valAddress: 'seivaloper1ummny4p645xraxc4m7nphf7vxawfzt3p5hn47t',
|
|
1059
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
1060
|
+
asset: { type: 'native' },
|
|
1061
|
+
})
|
|
984
1062
|
|
|
985
1063
|
expect(result).toMatch(/^0x[A-Fa-f0-9]+$/)
|
|
986
1064
|
expect(ethers.Transaction.from(result)).toMatchObject({
|
|
987
1065
|
value: seiStakingDelegationAmount,
|
|
988
1066
|
to: seiStakingRecipient,
|
|
989
1067
|
})
|
|
990
|
-
|
|
1068
|
+
const tx = ethers.Transaction.from(result)
|
|
1069
|
+
expect(tx.type).toBe(2)
|
|
1070
|
+
expect(tx.gasPrice).toBeNull()
|
|
1071
|
+
expect(typeof tx.maxFeePerGas).toBe('bigint')
|
|
1072
|
+
expect(typeof tx.maxPriorityFeePerGas).toBe('bigint')
|
|
1073
|
+
expect(tx.maxFeePerGas).toBeGreaterThan(0n)
|
|
1074
|
+
expect(tx.maxPriorityFeePerGas).toBeGreaterThan(0n)
|
|
991
1075
|
})
|
|
992
1076
|
})
|
|
993
1077
|
|
|
994
|
-
describe
|
|
995
|
-
|
|
996
|
-
'legacy',
|
|
997
|
-
(estimation: FeeEstimation): void => {
|
|
998
|
-
expect(estimation).toEqual({
|
|
999
|
-
value: expect.any(BigInt),
|
|
1000
|
-
parameters: {
|
|
1001
|
-
gasPrice: expect.any(BigInt),
|
|
1002
|
-
gasLimit: expect.any(BigInt),
|
|
1003
|
-
maxFeePerGas: null,
|
|
1004
|
-
maxPriorityFeePerGas: null,
|
|
1005
|
-
nextBaseFee: null,
|
|
1006
|
-
type: 0,
|
|
1007
|
-
},
|
|
1008
|
-
})
|
|
1009
|
-
expect(estimation.value).toBeGreaterThan(0)
|
|
1010
|
-
expect(estimation.parameters?.gasPrice).toBeGreaterThan(0)
|
|
1011
|
-
},
|
|
1012
|
-
],
|
|
1013
|
-
[
|
|
1014
|
-
'eip1559',
|
|
1015
|
-
(estimation: FeeEstimation): void => {
|
|
1016
|
-
expect(estimation).toEqual({
|
|
1017
|
-
value: expect.any(BigInt),
|
|
1018
|
-
parameters: {
|
|
1019
|
-
gasPrice: null,
|
|
1020
|
-
gasLimit: expect.any(BigInt),
|
|
1021
|
-
maxFeePerGas: expect.any(BigInt),
|
|
1022
|
-
maxPriorityFeePerGas: expect.any(BigInt),
|
|
1023
|
-
nextBaseFee: expect.any(BigInt),
|
|
1024
|
-
type: 2,
|
|
1025
|
-
},
|
|
1026
|
-
})
|
|
1027
|
-
expect(estimation.value).toBeGreaterThan(0)
|
|
1028
|
-
expect(estimation.parameters?.maxFeePerGas).toBeGreaterThan(0)
|
|
1029
|
-
expect(estimation.parameters?.maxPriorityFeePerGas).toBeGreaterThan(0)
|
|
1030
|
-
expect(estimation.parameters?.nextBaseFee).toBeGreaterThan(0)
|
|
1031
|
-
},
|
|
1032
|
-
],
|
|
1033
|
-
])('estimateFees for %s transaction', (mode, expectEstimationForMode) => {
|
|
1034
|
-
it('estimates fees for staking delegation', async () => {
|
|
1078
|
+
describe('estimateFees', () => {
|
|
1079
|
+
it('estimates fees for legacy staking delegation', async () => {
|
|
1035
1080
|
const result = await module.estimateFees(context, {
|
|
1036
|
-
type:
|
|
1081
|
+
type: 'staking-legacy',
|
|
1037
1082
|
intentType: 'staking' as const,
|
|
1038
1083
|
amount: seiStakingDelegationAmount,
|
|
1039
1084
|
mode: 'delegate',
|
|
@@ -1041,30 +1086,69 @@ describe('EVM Api (SEI Network)', () => {
|
|
|
1041
1086
|
recipient: seiStakingRecipient,
|
|
1042
1087
|
valAddress: 'seivaloper1ummny4p645xraxc4m7nphf7vxawfzt3p5hn47t',
|
|
1043
1088
|
data: { type: 'buffer', value: Buffer.from([]) },
|
|
1044
|
-
asset: {
|
|
1045
|
-
|
|
1089
|
+
asset: { type: 'native' },
|
|
1090
|
+
})
|
|
1091
|
+
|
|
1092
|
+
expect(result).toEqual({
|
|
1093
|
+
value: expect.any(BigInt),
|
|
1094
|
+
parameters: {
|
|
1095
|
+
gasPrice: expect.any(BigInt),
|
|
1096
|
+
gasLimit: expect.any(BigInt),
|
|
1097
|
+
maxFeePerGas: null,
|
|
1098
|
+
maxPriorityFeePerGas: null,
|
|
1099
|
+
nextBaseFee: null,
|
|
1100
|
+
type: 0,
|
|
1046
1101
|
},
|
|
1047
|
-
}
|
|
1102
|
+
})
|
|
1103
|
+
expect(result.value).toBeGreaterThan(0)
|
|
1104
|
+
expect(result.parameters?.gasPrice).toBeGreaterThan(0)
|
|
1105
|
+
})
|
|
1048
1106
|
|
|
1049
|
-
|
|
1107
|
+
it('estimates fees for eip1559 staking delegation', async () => {
|
|
1108
|
+
const result = await module.estimateFees(context, {
|
|
1109
|
+
type: 'staking-eip1559',
|
|
1110
|
+
intentType: 'staking' as const,
|
|
1111
|
+
amount: seiStakingDelegationAmount,
|
|
1112
|
+
mode: 'delegate',
|
|
1113
|
+
sender: seiStakingSender,
|
|
1114
|
+
recipient: seiStakingRecipient,
|
|
1115
|
+
valAddress: 'seivaloper1ummny4p645xraxc4m7nphf7vxawfzt3p5hn47t',
|
|
1116
|
+
data: { type: 'buffer', value: Buffer.from([]) },
|
|
1117
|
+
asset: { type: 'native' },
|
|
1118
|
+
})
|
|
1119
|
+
|
|
1120
|
+
expect(result).toEqual({
|
|
1121
|
+
value: expect.any(BigInt),
|
|
1122
|
+
parameters: {
|
|
1123
|
+
gasPrice: null,
|
|
1124
|
+
gasLimit: expect.any(BigInt),
|
|
1125
|
+
maxFeePerGas: expect.any(BigInt),
|
|
1126
|
+
maxPriorityFeePerGas: expect.any(BigInt),
|
|
1127
|
+
nextBaseFee: expect.any(BigInt),
|
|
1128
|
+
type: 2,
|
|
1129
|
+
},
|
|
1130
|
+
})
|
|
1131
|
+
expect(result.value).toBeGreaterThan(0)
|
|
1132
|
+
expect(result.parameters?.maxFeePerGas).toBeGreaterThan(0)
|
|
1133
|
+
expect(result.parameters?.maxPriorityFeePerGas).toBeGreaterThan(0)
|
|
1134
|
+
expect(result.parameters?.nextBaseFee).toBeGreaterThan(0)
|
|
1050
1135
|
})
|
|
1051
1136
|
})
|
|
1052
1137
|
})
|
|
1053
1138
|
|
|
1054
1139
|
describe('EVM Api (Zero Gravity)', () => {
|
|
1055
1140
|
let module: ReturnType<typeof createApi>
|
|
1056
|
-
const
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
uri: 'https://evmrpc.0g.ai',
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
const context = createMockEvmContext(config)
|
|
1141
|
+
const context = createMockEvmContext(
|
|
1142
|
+
createMockEvmConfigInfo({
|
|
1143
|
+
chainId: 16661,
|
|
1144
|
+
node: mkExternalNode({ uri: 'https://evmrpc.0g.ai' }),
|
|
1145
|
+
explorer: {
|
|
1146
|
+
type: 'etherscan' as const,
|
|
1147
|
+
uri: 'https://chainscan.0g.ai/open/api',
|
|
1148
|
+
maxLimit: 99, // use 99 so internal `limit + 1` probing stays within the explorer's hard max of 100
|
|
1149
|
+
},
|
|
1150
|
+
})
|
|
1151
|
+
)
|
|
1068
1152
|
|
|
1069
1153
|
beforeAll(() => {
|
|
1070
1154
|
module = createApi('zero_gravity')
|