@ledgerhq/coin-evm 5.3.3 → 5.3.6
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 +1 -1
- package/CHANGELOG.md +18 -0
- package/lib/config.d.ts +4 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/errors.d.ts +6 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +12 -1
- package/lib/errors.js.map +1 -1
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js +15 -19
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js +6 -4
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/withRetries.d.ts.map +1 -1
- package/lib/network/withRetries.js +13 -0
- package/lib/network/withRetries.js.map +1 -1
- package/lib/utils.d.ts +0 -2
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +0 -30
- package/lib/utils.js.map +1 -1
- package/lib-es/config.d.ts +4 -0
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/errors.d.ts +6 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +10 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js +16 -20
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js +7 -5
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/withRetries.d.ts.map +1 -1
- package/lib-es/network/withRetries.js +10 -0
- package/lib-es/network/withRetries.js.map +1 -1
- package/lib-es/utils.d.ts +0 -2
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +0 -28
- package/lib-es/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/api/index.integ.test.ts +0 -8
- package/src/api/index.zksync.integ.test.ts +38 -0
- package/src/config.ts +4 -0
- package/src/errors.ts +10 -0
- package/src/logic.test.ts +47 -62
- package/src/network/explorer/etherscan.test.ts +160 -134
- package/src/network/explorer/etherscan.ts +37 -27
- package/src/network/explorer/ledger.test.ts +60 -53
- package/src/network/explorer/ledger.ts +27 -22
- package/src/network/gasTracker/ledger.test.ts +18 -48
- package/src/network/node/rpc.test.ts +76 -66
- package/src/network/withRetries.test.ts +63 -0
- package/src/network/withRetries.ts +12 -0
- package/src/utils.test.ts +0 -86
- package/src/utils.ts +0 -41
- package/src/api/index.fantom.integ.test.ts +0 -103
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { PerformActionRequest } from 'ethers'
|
|
4
5
|
import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
5
6
|
import BigNumber from 'bignumber.js'
|
|
6
7
|
import { FeeData, FetchRequest, JsonRpcProvider, Network, Transaction } from 'ethers'
|
|
7
8
|
import { getCoinConfig } from '../../config'
|
|
8
9
|
import { GasEstimationError, InsufficientFunds, UnsupportedRpcMethodError } from '../../errors'
|
|
9
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
createMockEvmCoinConfig,
|
|
12
|
+
createMockEvmConfigInfo,
|
|
13
|
+
mkExternalNode,
|
|
14
|
+
} from '../../fixtures/context.fixtures'
|
|
10
15
|
import {
|
|
11
16
|
mkBlock,
|
|
12
17
|
mkTransactionReceipt,
|
|
@@ -60,16 +65,9 @@ describe('EVM Family', () => {
|
|
|
60
65
|
jest.resetAllMocks()
|
|
61
66
|
jest.spyOn(JsonRpcProvider.prototype, '_detectNetwork').mockResolvedValue(Network.from(1))
|
|
62
67
|
|
|
63
|
-
mockGetConfig.mockImplementation(()
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
node: {
|
|
67
|
-
type: 'external',
|
|
68
|
-
uri: 'my-rpc.com',
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
}
|
|
72
|
-
})
|
|
68
|
+
mockGetConfig.mockImplementation(() =>
|
|
69
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'my-rpc.com' }) })
|
|
70
|
+
)
|
|
73
71
|
|
|
74
72
|
jest
|
|
75
73
|
.spyOn(JsonRpcProvider.prototype, 'getFeeData')
|
|
@@ -134,7 +132,7 @@ describe('EVM Family', () => {
|
|
|
134
132
|
|
|
135
133
|
jest
|
|
136
134
|
.spyOn(JsonRpcProvider.prototype, 'broadcastTransaction')
|
|
137
|
-
.mockImplementation(async (signedTx: string)
|
|
135
|
+
.mockImplementation(async (signedTx: string) => {
|
|
138
136
|
if (
|
|
139
137
|
signedTx ===
|
|
140
138
|
'0x02f873012d85010c388d0085077715912682520894c2907efcce4011c491bbeda8a0fa63ba7aab596c87038d7ea4c6800080c001a0bbffe7ba303ab03f697d64672c4a288ae863df8a62ffc67ba72872ce8c227f6fa01261e7c9f06af13631f03fad9b88d3c48931d353b6b41b4072fddcca5ec41628'
|
|
@@ -150,9 +148,9 @@ describe('EVM Family', () => {
|
|
|
150
148
|
throw new Error('any error')
|
|
151
149
|
}
|
|
152
150
|
|
|
153
|
-
return {
|
|
151
|
+
return mkTransactionResponse({
|
|
154
152
|
hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
|
|
155
|
-
}
|
|
153
|
+
})
|
|
156
154
|
})
|
|
157
155
|
})
|
|
158
156
|
|
|
@@ -688,12 +686,14 @@ describe('EVM Family', () => {
|
|
|
688
686
|
|
|
689
687
|
describe('getGasEstimation', () => {
|
|
690
688
|
it('should return the expected payload', async () => {
|
|
691
|
-
jest
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
689
|
+
jest
|
|
690
|
+
.spyOn(JsonRpcProvider.prototype, '_perform')
|
|
691
|
+
.mockImplementation(async (req: PerformActionRequest) => {
|
|
692
|
+
if (req.method === 'estimateGas') {
|
|
693
|
+
return 5n
|
|
694
|
+
}
|
|
695
|
+
return null
|
|
696
|
+
})
|
|
697
697
|
expect(
|
|
698
698
|
await nodeApi.getGasEstimation(currencyId, address, {
|
|
699
699
|
recipient: '0x0000000000000000000000000000000000000000',
|
|
@@ -704,12 +704,14 @@ describe('EVM Family', () => {
|
|
|
704
704
|
})
|
|
705
705
|
|
|
706
706
|
it('should throw a GasEstimationError in case of error', async () => {
|
|
707
|
-
jest
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
707
|
+
jest
|
|
708
|
+
.spyOn(JsonRpcProvider.prototype, '_perform')
|
|
709
|
+
.mockImplementation(async (req: PerformActionRequest) => {
|
|
710
|
+
if (req.method === 'estimateGas') {
|
|
711
|
+
throw new Error('fail')
|
|
712
|
+
}
|
|
713
|
+
return null
|
|
714
|
+
})
|
|
713
715
|
|
|
714
716
|
await expect(
|
|
715
717
|
nodeApi.getGasEstimation(currencyId, address, {
|
|
@@ -886,12 +888,13 @@ describe('EVM Family', () => {
|
|
|
886
888
|
])(
|
|
887
889
|
'forwards feeHistoryRewardPercentile %i to eth_feeHistory',
|
|
888
890
|
async (configured, expected) => {
|
|
889
|
-
mockGetConfig.mockImplementation(()
|
|
890
|
-
|
|
891
|
-
|
|
891
|
+
mockGetConfig.mockImplementation(() =>
|
|
892
|
+
createMockEvmCoinConfig({
|
|
893
|
+
chainId: 1,
|
|
894
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
892
895
|
feeHistoryRewardPercentile: configured,
|
|
893
|
-
}
|
|
894
|
-
|
|
896
|
+
})
|
|
897
|
+
)
|
|
895
898
|
const sendSpy = stubFeeHistory()
|
|
896
899
|
|
|
897
900
|
await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, eip1559Tx)
|
|
@@ -901,13 +904,14 @@ describe('EVM Family', () => {
|
|
|
901
904
|
)
|
|
902
905
|
|
|
903
906
|
it('combines feeHistoryBlockCount and feeHistoryRewardPercentile when both configured', async () => {
|
|
904
|
-
mockGetConfig.mockImplementation(()
|
|
905
|
-
|
|
906
|
-
|
|
907
|
+
mockGetConfig.mockImplementation(() =>
|
|
908
|
+
createMockEvmCoinConfig({
|
|
909
|
+
chainId: 1,
|
|
910
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
907
911
|
feeHistoryBlockCount: 20,
|
|
908
912
|
feeHistoryRewardPercentile: 75,
|
|
909
|
-
}
|
|
910
|
-
|
|
913
|
+
})
|
|
914
|
+
)
|
|
911
915
|
const sendSpy = stubFeeHistory()
|
|
912
916
|
|
|
913
917
|
await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, eip1559Tx)
|
|
@@ -924,12 +928,13 @@ describe('EVM Family', () => {
|
|
|
924
928
|
])(
|
|
925
929
|
'forwards block count %i to eth_feeHistory as %s (hex-encoded)',
|
|
926
930
|
async (blockCount, expectedHex) => {
|
|
927
|
-
mockGetConfig.mockImplementation(()
|
|
928
|
-
|
|
929
|
-
|
|
931
|
+
mockGetConfig.mockImplementation(() =>
|
|
932
|
+
createMockEvmCoinConfig({
|
|
933
|
+
chainId: 1,
|
|
934
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
930
935
|
feeHistoryBlockCount: blockCount,
|
|
931
|
-
}
|
|
932
|
-
|
|
936
|
+
})
|
|
937
|
+
)
|
|
933
938
|
const sendSpy = stubFeeHistory()
|
|
934
939
|
|
|
935
940
|
await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, eip1559Tx)
|
|
@@ -939,12 +944,13 @@ describe('EVM Family', () => {
|
|
|
939
944
|
)
|
|
940
945
|
|
|
941
946
|
it('is not used on the legacy path (eth_feeHistory is never called)', async () => {
|
|
942
|
-
mockGetConfig.mockImplementation(()
|
|
943
|
-
|
|
944
|
-
|
|
947
|
+
mockGetConfig.mockImplementation(() =>
|
|
948
|
+
createMockEvmCoinConfig({
|
|
949
|
+
chainId: 1,
|
|
950
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
945
951
|
feeHistoryBlockCount: 50,
|
|
946
|
-
}
|
|
947
|
-
|
|
952
|
+
})
|
|
953
|
+
)
|
|
948
954
|
const sendSpy = jest
|
|
949
955
|
.spyOn(JsonRpcProvider.prototype, 'send')
|
|
950
956
|
.mockImplementation(async (method) => {
|
|
@@ -967,13 +973,14 @@ describe('EVM Family', () => {
|
|
|
967
973
|
})
|
|
968
974
|
|
|
969
975
|
it('combines block count and minGasPrice floor correctly', async () => {
|
|
970
|
-
mockGetConfig.mockImplementation(()
|
|
971
|
-
|
|
972
|
-
|
|
976
|
+
mockGetConfig.mockImplementation(() =>
|
|
977
|
+
createMockEvmCoinConfig({
|
|
978
|
+
chainId: 1,
|
|
979
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
973
980
|
feeHistoryBlockCount: 20,
|
|
974
981
|
minGasPrice: '20000000000', // 20 Gwei
|
|
975
|
-
}
|
|
976
|
-
|
|
982
|
+
})
|
|
983
|
+
)
|
|
977
984
|
const sendSpy = jest
|
|
978
985
|
.spyOn(JsonRpcProvider.prototype, 'send')
|
|
979
986
|
.mockImplementation(async (method) => {
|
|
@@ -999,12 +1006,13 @@ describe('EVM Family', () => {
|
|
|
999
1006
|
})
|
|
1000
1007
|
|
|
1001
1008
|
it('applies minGasPrice floor to maxPriorityFeePerGas (EIP-1559) when feeHistory reports a lower value', async () => {
|
|
1002
|
-
mockGetConfig.mockImplementation(()
|
|
1003
|
-
|
|
1004
|
-
|
|
1009
|
+
mockGetConfig.mockImplementation(() =>
|
|
1010
|
+
createMockEvmCoinConfig({
|
|
1011
|
+
chainId: 1,
|
|
1012
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
1005
1013
|
minGasPrice: '20000000000', // 20 Gwei floor
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1014
|
+
})
|
|
1015
|
+
)
|
|
1008
1016
|
|
|
1009
1017
|
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1010
1018
|
if (method === 'eth_feeHistory') {
|
|
@@ -1025,12 +1033,13 @@ describe('EVM Family', () => {
|
|
|
1025
1033
|
})
|
|
1026
1034
|
|
|
1027
1035
|
it('does not lower the priority fee when feeHistory already reports above the configured floor', async () => {
|
|
1028
|
-
mockGetConfig.mockImplementation(()
|
|
1029
|
-
|
|
1030
|
-
|
|
1036
|
+
mockGetConfig.mockImplementation(() =>
|
|
1037
|
+
createMockEvmCoinConfig({
|
|
1038
|
+
chainId: 1,
|
|
1039
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
1031
1040
|
minGasPrice: '1000000000', // 1 Gwei floor
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1041
|
+
})
|
|
1042
|
+
)
|
|
1034
1043
|
|
|
1035
1044
|
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1036
1045
|
if (method === 'eth_feeHistory') {
|
|
@@ -1049,12 +1058,13 @@ describe('EVM Family', () => {
|
|
|
1049
1058
|
})
|
|
1050
1059
|
|
|
1051
1060
|
it('applies minGasPrice floor from coin config for legacy txs when node reports lower', async () => {
|
|
1052
|
-
mockGetConfig.mockImplementation(()
|
|
1053
|
-
|
|
1054
|
-
|
|
1061
|
+
mockGetConfig.mockImplementation(() =>
|
|
1062
|
+
createMockEvmCoinConfig({
|
|
1063
|
+
chainId: 1,
|
|
1064
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
1055
1065
|
minGasPrice: '20000000000', // 20 Gwei
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1066
|
+
})
|
|
1067
|
+
)
|
|
1058
1068
|
|
|
1059
1069
|
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1060
1070
|
if (method === 'eth_getBlockByNumber') {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
5
|
+
import { RateLimitError } from '../errors'
|
|
6
|
+
import { withRetries } from './withRetries'
|
|
7
|
+
|
|
8
|
+
jest.mock('@ledgerhq/coin-module-framework/promises')
|
|
9
|
+
jest.mocked(delay).mockResolvedValue(undefined)
|
|
10
|
+
|
|
11
|
+
describe('EVM Family', () => {
|
|
12
|
+
describe('network/withRetries.ts', () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
jest.clearAllMocks()
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('should retry a transient error until it succeeds', async () => {
|
|
18
|
+
const fn = jest.fn().mockRejectedValueOnce(new Error('boom')).mockResolvedValueOnce('ok')
|
|
19
|
+
|
|
20
|
+
await expect(withRetries(fn, 2, 10)).resolves.toBe('ok')
|
|
21
|
+
expect(fn).toHaveBeenCalledTimes(2)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('should surface an external node 429 as a RateLimitError without retrying', async () => {
|
|
25
|
+
// ethers escalates a 429 into a 599 SERVER_ERROR, keeping the original status in the
|
|
26
|
+
// statusMessage. This is the exact `${statusCode} ${statusMessage}` shape it produces.
|
|
27
|
+
const escalated = Object.assign(new Error('server response 599'), {
|
|
28
|
+
code: 'SERVER_ERROR',
|
|
29
|
+
info: {
|
|
30
|
+
responseStatus:
|
|
31
|
+
'599 CLIENT ESCALATED SERVER ERROR (429 Too Many Requests; exceeded maximum retry limit)',
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
const fn = jest.fn().mockRejectedValue(escalated)
|
|
35
|
+
|
|
36
|
+
await expect(withRetries(fn, 5, 10)).rejects.toBeInstanceOf(RateLimitError)
|
|
37
|
+
// a rate limit is not transient: it must not consume the retry budget
|
|
38
|
+
expect(fn).toHaveBeenCalledTimes(1)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('should surface a Ledger node 429 as a RateLimitError without retrying', async () => {
|
|
42
|
+
const rateLimitError = Object.assign(new Error('Request failed with status code 429'), {
|
|
43
|
+
isAxiosError: true,
|
|
44
|
+
response: { status: 429 },
|
|
45
|
+
})
|
|
46
|
+
const fn = jest.fn().mockRejectedValue(rateLimitError)
|
|
47
|
+
|
|
48
|
+
await expect(withRetries(fn, 5, 10)).rejects.toBeInstanceOf(RateLimitError)
|
|
49
|
+
expect(fn).toHaveBeenCalledTimes(1)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('should keep retrying a non-429 SERVER_ERROR', async () => {
|
|
53
|
+
const serverError = Object.assign(new Error('server response 503'), {
|
|
54
|
+
code: 'SERVER_ERROR',
|
|
55
|
+
info: { responseStatus: '503 Service Unavailable' },
|
|
56
|
+
})
|
|
57
|
+
const fn = jest.fn().mockRejectedValue(serverError)
|
|
58
|
+
|
|
59
|
+
await expect(withRetries(fn, 2, 10)).rejects.toBe(serverError)
|
|
60
|
+
expect(fn).toHaveBeenCalledTimes(3)
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
})
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
5
|
+
import axios from 'axios'
|
|
6
|
+
import { isError } from 'ethers'
|
|
7
|
+
import { RateLimitError } from '../errors'
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Executes an async function and retries on failure.
|
|
@@ -18,6 +21,15 @@ export async function withRetries<T>(
|
|
|
18
21
|
try {
|
|
19
22
|
return await fn()
|
|
20
23
|
} catch (e) {
|
|
24
|
+
// External nodes go through ethers, which escalates a 429 into a 599 SERVER_ERROR whose
|
|
25
|
+
// responseStatus (`${statusCode} ${statusMessage}`) embeds the original status — hence the
|
|
26
|
+
// substring match rather than an equality check. Ledger nodes reject with plain axios errors.
|
|
27
|
+
if (
|
|
28
|
+
(isError(e, 'SERVER_ERROR') && String(e.info?.responseStatus ?? '').includes('429')) ||
|
|
29
|
+
(axios.isAxiosError(e) && e.response?.status === 429)
|
|
30
|
+
) {
|
|
31
|
+
throw new RateLimitError()
|
|
32
|
+
}
|
|
21
33
|
if (retries > 0) {
|
|
22
34
|
await delay(delayMs)
|
|
23
35
|
return withRetries(fn, retries - 1, delayMs)
|
package/src/utils.test.ts
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
import {
|
|
5
5
|
buildSmartContractDetails,
|
|
6
6
|
isSmartContractInput,
|
|
7
|
-
nftDisabled,
|
|
8
|
-
nftEnabled,
|
|
9
7
|
parseDecimalIntegerPart,
|
|
10
8
|
safeEncodeEIP55,
|
|
11
9
|
} from './utils'
|
|
@@ -88,87 +86,3 @@ describe('parseDecimalIntegerPart', () => {
|
|
|
88
86
|
}
|
|
89
87
|
)
|
|
90
88
|
})
|
|
91
|
-
|
|
92
|
-
describe('nftEnabled', () => {
|
|
93
|
-
beforeEach(() => {
|
|
94
|
-
process.env.NFT_CURRENCIES = JSON.stringify([])
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('should return false when currency is null or undefined', () => {
|
|
98
|
-
expect(nftEnabled(null)).toEqual(false)
|
|
99
|
-
expect(nftEnabled(undefined)).toEqual(false)
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('should return false when NFT_CURRENCIES env does not include currency', () => {
|
|
103
|
-
process.env.NFT_CURRENCIES = JSON.stringify(['base', 'polygon'])
|
|
104
|
-
expect(nftEnabled('ethereum')).toEqual(false)
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('should return true when NFT_CURRENCIES env include currency', () => {
|
|
108
|
-
process.env.NFT_CURRENCIES = JSON.stringify(['base', 'ethereum', 'polygon'])
|
|
109
|
-
expect(nftEnabled('ethereum')).toEqual(true)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
it.each([
|
|
113
|
-
'',
|
|
114
|
-
'word',
|
|
115
|
-
'a simple sentence',
|
|
116
|
-
'0x66c4371aE8FFeD2ec1c2EBbbcCfb7E494181E1E3',
|
|
117
|
-
'[]}',
|
|
118
|
-
'{ [] }',
|
|
119
|
-
])('should return false when NFT_CURRENCIES is not a valid JSON (%s)', (value) => {
|
|
120
|
-
process.env.NFT_CURRENCIES = value
|
|
121
|
-
expect(nftEnabled('ethereum')).toEqual(false)
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('should return false when NFT_CURRENCIES is not an array', () => {
|
|
125
|
-
// A new config not supported for example (feature flag like)
|
|
126
|
-
process.env.NFT_CURRENCIES = JSON.stringify({
|
|
127
|
-
enabled: true,
|
|
128
|
-
params: { families: ['ethereum'] },
|
|
129
|
-
})
|
|
130
|
-
expect(nftEnabled('ethereum')).toBe(false)
|
|
131
|
-
})
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
describe('nftDisabled', () => {
|
|
135
|
-
beforeEach(() => {
|
|
136
|
-
process.env.NFT_CURRENCIES = JSON.stringify([])
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
it('should return false when currency is null or undefined', () => {
|
|
140
|
-
expect(nftDisabled(null)).toEqual(true)
|
|
141
|
-
expect(nftDisabled(undefined)).toEqual(true)
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('should return true when NFT_CURRENCIES env does not include currency', () => {
|
|
145
|
-
process.env.NFT_CURRENCIES = JSON.stringify(['base', 'polygon'])
|
|
146
|
-
expect(nftDisabled('ethereum')).toEqual(true)
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
it('should return false when NFT_CURRENCIES env include currency', () => {
|
|
150
|
-
process.env.NFT_CURRENCIES = JSON.stringify(['base', 'ethereum', 'polygon'])
|
|
151
|
-
expect(nftDisabled('ethereum')).toEqual(false)
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
it.each([
|
|
155
|
-
'',
|
|
156
|
-
'word',
|
|
157
|
-
'a simple sentence',
|
|
158
|
-
'0x66c4371aE8FFeD2ec1c2EBbbcCfb7E494181E1E3',
|
|
159
|
-
'[]}',
|
|
160
|
-
'{ [] }',
|
|
161
|
-
])('should return true when NFT_CURRENCIES is not a valid JSON (%s)', (value) => {
|
|
162
|
-
process.env.NFT_CURRENCIES = value
|
|
163
|
-
expect(nftDisabled('ethereum')).toEqual(true)
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
it('should return true when NFT_CURRENCIES is not an array', () => {
|
|
167
|
-
// A new config not supported for example (feature flag like)
|
|
168
|
-
process.env.NFT_CURRENCIES = JSON.stringify({
|
|
169
|
-
enabled: true,
|
|
170
|
-
params: { families: ['ethereum'] },
|
|
171
|
-
})
|
|
172
|
-
expect(nftDisabled('ethereum')).toBe(true)
|
|
173
|
-
})
|
|
174
|
-
})
|
package/src/utils.ts
CHANGED
|
@@ -371,44 +371,3 @@ export type EvmStakingIntent = StakingTransactionIntent & {
|
|
|
371
371
|
export function isStakingIntent(intent: TransactionIntent): intent is EvmStakingIntent {
|
|
372
372
|
return intent.intentType === 'staking'
|
|
373
373
|
}
|
|
374
|
-
|
|
375
|
-
export function nftEnabled(currencyId: string | undefined | null): boolean {
|
|
376
|
-
let parsedNftCurrencies: unknown = undefined
|
|
377
|
-
if (process.env.NFT_CURRENCIES) {
|
|
378
|
-
try {
|
|
379
|
-
parsedNftCurrencies = JSON.parse(process.env.NFT_CURRENCIES)
|
|
380
|
-
} catch (error) {
|
|
381
|
-
log(
|
|
382
|
-
'EVM Family - utils.ts',
|
|
383
|
-
'Env variable NFT_CURRENCIES is malformed, expecting a string array',
|
|
384
|
-
{
|
|
385
|
-
envName: 'NFT_CURRENCIES',
|
|
386
|
-
envValue: process.env.NFT_CURRENCIES,
|
|
387
|
-
error,
|
|
388
|
-
}
|
|
389
|
-
)
|
|
390
|
-
|
|
391
|
-
return false
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (!Array.isArray(parsedNftCurrencies)) {
|
|
396
|
-
log(
|
|
397
|
-
'EVM Family - utils.ts',
|
|
398
|
-
'Env variable NFT_CURRENCIES is malformed, expecting a string array',
|
|
399
|
-
{
|
|
400
|
-
envName: 'NFT_CURRENCIES',
|
|
401
|
-
envValue: process.env.NFT_CURRENCIES,
|
|
402
|
-
}
|
|
403
|
-
)
|
|
404
|
-
|
|
405
|
-
return false
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
return Boolean(currencyId && parsedNftCurrencies.includes(currencyId))
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// Simple utility function, to ease reading code
|
|
412
|
-
export function nftDisabled(currencyId: string | undefined | null): boolean {
|
|
413
|
-
return !nftEnabled(currencyId)
|
|
414
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { EvmConfig } from '../config'
|
|
5
|
-
import { createMockEvmContext } from '../fixtures/context.fixtures'
|
|
6
|
-
import { safeEncodeEIP55 } from '../utils'
|
|
7
|
-
import { createApi } from './index'
|
|
8
|
-
|
|
9
|
-
describe('Fantom (etherscan explorer)', () => {
|
|
10
|
-
describe('getBlock', () => {
|
|
11
|
-
let module: ReturnType<typeof createApi>
|
|
12
|
-
|
|
13
|
-
const fantomConfig: EvmConfig = {
|
|
14
|
-
chainId: 250,
|
|
15
|
-
name: 'Fantom',
|
|
16
|
-
node: {
|
|
17
|
-
type: 'external',
|
|
18
|
-
uri: 'https://rpcapi.fantom.network',
|
|
19
|
-
},
|
|
20
|
-
explorer: {
|
|
21
|
-
type: 'blockscout',
|
|
22
|
-
uri: 'https://ftmscout.com/api',
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
beforeAll(() => {
|
|
26
|
-
module = createApi('fantom')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should include internal native transfer in block transaction', async () => {
|
|
30
|
-
// for fantom, blockscout explorer returns no internal transactions for block 120647648, even though there are 3 !!
|
|
31
|
-
// ❯ curl -s "https://ftmscout.com/api?module=account&action=txlistinternal&startblock=120647648&endblock=120647648"
|
|
32
|
-
// {"message":"No internal transactions found","result":[],"status":"0"}
|
|
33
|
-
|
|
34
|
-
// ❯ curl -s -X POST "https://rpcapi.fantom.network" -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"trace_block","params":["0x730efe0"]}' | jq '.result | length'
|
|
35
|
-
// 6
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
const blockHeight = 120647648
|
|
39
|
-
const expectedAmount = 0x15a7c087e1eb7e18n
|
|
40
|
-
|
|
41
|
-
/*
|
|
42
|
-
* Fantom block 120647648 contains (among others) 3 internal native transfers with value 0x15a7c087e1eb7e18:
|
|
43
|
-
* - 0x59e8070de88cc1e4085293efd08aad4fba2ef6e0 → 0x44ceb2cdd0e9891f26ce5b96d2a7a3017304c25f
|
|
44
|
-
* - 0x44ceb2cdd0e9891f26ce5b96d2a7a3017304c25f → 0x68e369edc0d374f86295690cbaa981ee3709c061
|
|
45
|
-
* - 0x68e369edc0d374f86295690cbaa981ee3709c061 → 0x10bb279126abd92d886aa3f2a60955c28bf14926
|
|
46
|
-
*/
|
|
47
|
-
const addr1 = safeEncodeEIP55('0x59e8070de88cc1e4085293efd08aad4fba2ef6e0')
|
|
48
|
-
const addr2 = safeEncodeEIP55('0x44ceb2cdd0e9891f26ce5b96d2a7a3017304c25f')
|
|
49
|
-
const addr3 = safeEncodeEIP55('0x68e369edc0d374f86295690cbaa981ee3709c061')
|
|
50
|
-
const addr4 = safeEncodeEIP55('0x10bb279126abd92d886aa3f2a60955c28bf14926')
|
|
51
|
-
|
|
52
|
-
const block = await module.getBlock(createMockEvmContext(fantomConfig), blockHeight)
|
|
53
|
-
|
|
54
|
-
expect(block.info.height).toBe(blockHeight)
|
|
55
|
-
|
|
56
|
-
const tx = block.transactions.find(
|
|
57
|
-
(t) => t.hash === '0x18815c2073a78c2264b89ee4b4a9267eb31c4c0a91b9d4d751ddd84b26584493'
|
|
58
|
-
)
|
|
59
|
-
expect(tx!.operations).toContainEqual({
|
|
60
|
-
type: 'transfer',
|
|
61
|
-
address: addr1,
|
|
62
|
-
peer: addr2,
|
|
63
|
-
asset: { type: 'native' },
|
|
64
|
-
amount: -expectedAmount,
|
|
65
|
-
})
|
|
66
|
-
expect(tx!.operations).toContainEqual({
|
|
67
|
-
type: 'transfer',
|
|
68
|
-
address: addr2,
|
|
69
|
-
peer: addr1,
|
|
70
|
-
asset: { type: 'native' },
|
|
71
|
-
amount: expectedAmount,
|
|
72
|
-
})
|
|
73
|
-
expect(tx!.operations).toContainEqual({
|
|
74
|
-
type: 'transfer',
|
|
75
|
-
address: addr2,
|
|
76
|
-
peer: addr3,
|
|
77
|
-
asset: { type: 'native' },
|
|
78
|
-
amount: -expectedAmount,
|
|
79
|
-
})
|
|
80
|
-
expect(tx!.operations).toContainEqual({
|
|
81
|
-
type: 'transfer',
|
|
82
|
-
address: addr3,
|
|
83
|
-
peer: addr2,
|
|
84
|
-
asset: { type: 'native' },
|
|
85
|
-
amount: expectedAmount,
|
|
86
|
-
})
|
|
87
|
-
expect(tx!.operations).toContainEqual({
|
|
88
|
-
type: 'transfer',
|
|
89
|
-
address: addr3,
|
|
90
|
-
peer: addr4,
|
|
91
|
-
asset: { type: 'native' },
|
|
92
|
-
amount: -expectedAmount,
|
|
93
|
-
})
|
|
94
|
-
expect(tx!.operations).toContainEqual({
|
|
95
|
-
type: 'transfer',
|
|
96
|
-
address: addr4,
|
|
97
|
-
peer: addr3,
|
|
98
|
-
asset: { type: 'native' },
|
|
99
|
-
amount: expectedAmount,
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
})
|
|
103
|
-
})
|