@ledgerhq/coin-evm 16.2.0 → 16.2.4

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/lib/network/explorer/etherscan.d.ts +12 -0
  3. package/lib/network/explorer/etherscan.d.ts.map +1 -1
  4. package/lib/network/explorer/etherscan.js +22 -12
  5. package/lib/network/explorer/etherscan.js.map +1 -1
  6. package/lib/network/gasTracker/ledger.js +2 -2
  7. package/lib/network/gasTracker/ledger.js.map +1 -1
  8. package/lib/network/node/rpc.common.d.ts.map +1 -1
  9. package/lib/network/node/rpc.common.js +31 -6
  10. package/lib/network/node/rpc.common.js.map +1 -1
  11. package/lib-es/network/explorer/etherscan.d.ts +12 -0
  12. package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
  13. package/lib-es/network/explorer/etherscan.js +22 -12
  14. package/lib-es/network/explorer/etherscan.js.map +1 -1
  15. package/lib-es/network/gasTracker/ledger.js +2 -2
  16. package/lib-es/network/gasTracker/ledger.js.map +1 -1
  17. package/lib-es/network/node/rpc.common.d.ts.map +1 -1
  18. package/lib-es/network/node/rpc.common.js +31 -6
  19. package/lib-es/network/node/rpc.common.js.map +1 -1
  20. package/package.json +9 -3
  21. package/src/api/tests/getBlock.integ.test.ts +1 -1
  22. package/src/api/tests/index.monad_testnet.integ.test.ts +20 -20
  23. package/src/api/tests/index.unichain.integ.test.ts +46 -0
  24. package/src/logic/tests/combine.test.ts +1 -1
  25. package/src/logic/tests/getStakes.test.ts +7 -0
  26. package/src/network/explorer/etherscan.ts +25 -13
  27. package/src/network/gasTracker/ledger.ts +2 -2
  28. package/src/network/node/rpc.common.ts +46 -6
  29. package/src/network/tests/explorer/etherscan.test.ts +104 -36
  30. package/src/network/tests/gasTracker/ledger.test.ts +52 -0
  31. package/src/network/tests/node/rpc.test.ts +58 -4
  32. package/.oxlintrc.json +0 -94
  33. package/docs/abis.md +0 -20
  34. package/docs/adapters.md +0 -10
  35. package/docs/evm-family-integration-process/README.md +0 -102
  36. package/docs/getBlock-internal-txs-schema.md +0 -104
  37. package/docs/logic.md +0 -17
  38. package/docs/network/explorer/etherscan.md +0 -35
  39. package/docs/network/explorer/index.md +0 -7
  40. package/docs/network/explorer/ledger.md +0 -22
  41. package/docs/network/gasTracker/index.md +0 -8
  42. package/docs/network/gasTracker/ledger.md +0 -13
  43. package/docs/network/node/index.md +0 -10
  44. package/docs/network/node/ledger.md +0 -47
  45. package/docs/network/node/rpc.md +0 -42
  46. package/docs/types.md +0 -18
  47. package/jest.config.js +0 -15
  48. package/jest.integ.config.js +0 -8
  49. package/knip.json +0 -30
  50. package/tsconfig.build.json +0 -14
  51. package/tsconfig.json +0 -14
@@ -21,8 +21,8 @@ type GasTracker = {
21
21
  // update of the explorer backend to support EIP1559, we should be able to
22
22
  // update this config without having to release a new version of the app?
23
23
  const explorerIdGasTrackerMap = new Map<string, GasTracker>([
24
- ['avax', { compatibilty: { eip1559: false } }],
25
- ['bnb', { compatibilty: { eip1559: false } }],
24
+ ['avax', { compatibilty: { eip1559: true } }],
25
+ ['bnb', { compatibilty: { eip1559: true } }],
26
26
  ['eth', { compatibilty: { eip1559: true } }],
27
27
  ['etc', { compatibilty: { eip1559: false } }],
28
28
  ['matic', { compatibilty: { eip1559: true } }],
@@ -111,6 +111,28 @@ function makeErc20Transfer(
111
111
  value: BigInt(log.data).toString(),
112
112
  }
113
113
  }
114
+
115
+ /**
116
+ * Some wrapped-native implementations emit both their WETH-style Deposit/Withdrawal
117
+ * event and the equivalent ERC-20 Transfer mint/burn. Keep the canonical Transfer
118
+ * in that case, so one wrap/unwrap produces one token transfer.
119
+ */
120
+ function hasEquivalentErc20Transfer(
121
+ transfers: ReadonlyArray<ERC20Transfer>,
122
+ log: LogWithAddress,
123
+ from: string,
124
+ to: string
125
+ ): boolean {
126
+ const assetReference = log.address.toLowerCase()
127
+ const value = BigInt(log.data).toString()
128
+ return transfers.some(
129
+ (transfer) =>
130
+ transfer.asset.assetReference.toLowerCase() === assetReference &&
131
+ transfer.from.toLowerCase() === from.toLowerCase() &&
132
+ transfer.to.toLowerCase() === to.toLowerCase() &&
133
+ transfer.value === value
134
+ )
135
+ }
114
136
  /**
115
137
  * Parse ERC20 Transfer events from transaction receipt logs.
116
138
  *
@@ -150,6 +172,20 @@ export function parseERC20TransfersFromLogs(
150
172
  logs: ReadonlyArray<LogWithAddress>,
151
173
  logger: Logger
152
174
  ): ERC20Transfer[] {
175
+ const erc20Transfers = logs.flatMap((log) => {
176
+ if (!isSystemLog(log) && isTransfer(log)) {
177
+ return [
178
+ makeErc20Transfer(
179
+ log,
180
+ topicToAddress(log.topics[1], logger),
181
+ topicToAddress(log.topics[2], logger),
182
+ logger
183
+ ),
184
+ ]
185
+ }
186
+ return []
187
+ })
188
+
153
189
  return logs.flatMap((log) => {
154
190
  // These mimic an ERC20 `Transfer` on a token that does not exist.
155
191
  if (isSystemLog(log)) {
@@ -166,14 +202,18 @@ export function parseERC20TransfersFromLogs(
166
202
  ]
167
203
  }
168
204
  if (isWethDeposit(log)) {
169
- return [
170
- makeErc20Transfer(log, ZERO_ADDRESS_HEX, topicToAddress(log.topics[1], logger), logger),
171
- ]
205
+ const to = topicToAddress(log.topics[1], logger)
206
+ if (hasEquivalentErc20Transfer(erc20Transfers, log, ZERO_ADDRESS_HEX, to)) {
207
+ return []
208
+ }
209
+ return [makeErc20Transfer(log, ZERO_ADDRESS_HEX, to, logger)]
172
210
  }
173
211
  if (isWethWithdrawal(log)) {
174
- return [
175
- makeErc20Transfer(log, topicToAddress(log.topics[1], logger), ZERO_ADDRESS_HEX, logger),
176
- ]
212
+ const from = topicToAddress(log.topics[1], logger)
213
+ if (hasEquivalentErc20Transfer(erc20Transfers, log, from, ZERO_ADDRESS_HEX)) {
214
+ return []
215
+ }
216
+ return [makeErc20Transfer(log, from, ZERO_ADDRESS_HEX, logger)]
177
217
  }
178
218
  if (isMint(log)) {
179
219
  return [
@@ -134,9 +134,9 @@ describe('EVM Family', () => {
134
134
  const spy = jest.spyOn(axios, 'request').mockImplementation(async () => {
135
135
  if (retries) {
136
136
  --retries
137
- return { data: { message: 'NOTOK' } }
137
+ return { data: { status: '0', message: 'NOTOK', result: 'Max rate limit reached' } }
138
138
  }
139
- return { data: { result: true } }
139
+ return { data: { status: '1', message: 'OK', result: true } }
140
140
  })
141
141
  const response = await ETHERSCAN_API.fetchWithRetries({}, retries)
142
142
 
@@ -145,6 +145,57 @@ describe('EVM Family', () => {
145
145
  expect(spy).toHaveBeenCalledTimes(3)
146
146
  })
147
147
 
148
+ it('should throw without retrying when the explorer reports a query timeout', async () => {
149
+ const spy = jest.spyOn(axios, 'request').mockResolvedValue({
150
+ data: {
151
+ status: '0',
152
+ message: 'Query Timeout occured. Please select a smaller result dataset',
153
+ result: null,
154
+ },
155
+ })
156
+
157
+ await expect(
158
+ ETHERSCAN_API.fetchWithRetries({}, ETHERSCAN_API.DEFAULT_RETRIES_API)
159
+ ).rejects.toBeInstanceOf(EtherscanAPIError)
160
+ // the same query times out again on every retry
161
+ expect(spy).toHaveBeenCalledTimes(1)
162
+ })
163
+
164
+ it.each([
165
+ ['an unknown error', 'Invalid address format', null],
166
+ ['an error string', 'NOTOK', 'Max rate limit reached'],
167
+ ])(
168
+ 'should retry, then throw, when the explorer reports %s instead of a list',
169
+ async (_, message, result) => {
170
+ const spy = jest.spyOn(axios, 'request').mockResolvedValue({
171
+ data: { status: '0', message, result },
172
+ })
173
+
174
+ await expect(ETHERSCAN_API.fetchWithRetries({}, 1)).rejects.toBeInstanceOf(
175
+ EtherscanAPIError
176
+ )
177
+ expect(spy).toHaveBeenCalledTimes(2)
178
+ }
179
+ )
180
+
181
+ it('should return an empty list as is', async () => {
182
+ jest.spyOn(axios, 'request').mockResolvedValueOnce({
183
+ data: { status: '0', message: 'No transactions found', result: [] },
184
+ })
185
+
186
+ await expect(ETHERSCAN_API.fetchWithRetries({}, 0)).resolves.toEqual([])
187
+ })
188
+
189
+ it('should throw on a caller-supplied error message even with a list result', async () => {
190
+ jest.spyOn(axios, 'request').mockResolvedValueOnce({
191
+ data: { status: '0', message: 'No internal transactions found', result: [] },
192
+ })
193
+
194
+ await expect(
195
+ ETHERSCAN_API.fetchWithRetries({}, 0, ['No internal transactions found'])
196
+ ).rejects.toBeInstanceOf(EtherscanAPIError)
197
+ })
198
+
148
199
  it('should surface a 429 HTTP response as RateLimitError without retrying', async () => {
149
200
  const rateLimitError = Object.assign(new Error('Request failed with status code 429'), {
150
201
  isAxiosError: true,
@@ -178,32 +229,48 @@ describe('EVM Family', () => {
178
229
  ['ERC20', ETHERSCAN_API.getTokenOperations],
179
230
  ['ERC721', ETHERSCAN_API.getERC721Operations],
180
231
  ['ERC1155', ETHERSCAN_API.getERC1155Operations],
181
- ])('%s operations with non-array explorer results', (_, getOperations) => {
232
+ ])('%s operations with status "0" explorer results', (_, getOperations) => {
182
233
  afterEach(() => {
183
234
  jest.clearAllMocks()
184
235
  })
185
236
 
186
- it.each([null, 'No transactions found'])(
187
- 'returns an empty result when the explorer returns %p',
188
- async (result) => {
189
- jest.spyOn(axios, 'request').mockResolvedValueOnce({
190
- data: { status: '0', message: 'No transactions found', result },
191
- })
237
+ it('returns an empty result when the explorer returns an empty list', async () => {
238
+ jest.spyOn(axios, 'request').mockResolvedValueOnce({
239
+ data: { status: '0', message: 'No transactions found', result: [] },
240
+ })
192
241
 
193
- const response = await getOperations({
194
- config,
195
- address,
196
- fromBlock: 0,
197
- sort: 'asc',
198
- logger: testLogger,
199
- })
242
+ const response = await getOperations({
243
+ config,
244
+ address,
245
+ fromBlock: 0,
246
+ sort: 'asc',
247
+ logger: testLogger,
248
+ })
200
249
 
201
- expect(response).toEqual({
202
- operations: [],
203
- isDone: true,
204
- boundBlock: 0,
205
- isPageFull: true,
250
+ expect(response).toEqual({
251
+ operations: [],
252
+ isDone: true,
253
+ boundBlock: 0,
254
+ isPageFull: true,
255
+ })
256
+ })
257
+
258
+ it.each([null, 'Max rate limit reached'])(
259
+ 'throws when the explorer returns %p instead of a list',
260
+ async (result) => {
261
+ jest.spyOn(axios, 'request').mockResolvedValue({
262
+ data: { status: '0', message: 'NOTOK', result },
206
263
  })
264
+
265
+ await expect(
266
+ getOperations({
267
+ config,
268
+ address,
269
+ fromBlock: 0,
270
+ sort: 'asc',
271
+ logger: testLogger,
272
+ })
273
+ ).rejects.toBeInstanceOf(EtherscanAPIError)
207
274
  }
208
275
  )
209
276
  })
@@ -1547,23 +1614,24 @@ describe('EVM Family', () => {
1547
1614
  )
1548
1615
  })
1549
1616
 
1550
- it('should return empty operations when API returns null result (e.g. Monad Testnet explorer)', async () => {
1551
- // Some explorers (e.g. Monad Testnet) return `{"status":"0","message":"No transactions found","result":null}`
1552
- // instead of `{"result":[]}` for empty internal transaction lists.
1553
- jest.spyOn(axios, 'request').mockResolvedValueOnce({
1554
- data: { status: '0', message: 'No transactions found', result: null },
1555
- })
1556
-
1557
- const response = await ETHERSCAN_API.getInternalOperations({
1558
- config,
1559
- address: address,
1560
- fromBlock: 0,
1561
- sort: 'asc',
1562
- logger: testLogger,
1617
+ it('should throw when API returns a null result instead of a list', async () => {
1618
+ jest.spyOn(axios, 'request').mockResolvedValue({
1619
+ data: {
1620
+ status: '0',
1621
+ message: 'Query Timeout occured. Please select a smaller result dataset',
1622
+ result: null,
1623
+ },
1563
1624
  })
1564
1625
 
1565
- expect(response.operations).toEqual([])
1566
- expect(response.isDone).toBe(true)
1626
+ await expect(
1627
+ ETHERSCAN_API.getInternalOperations({
1628
+ config,
1629
+ address: address,
1630
+ fromBlock: 0,
1631
+ sort: 'asc',
1632
+ logger: testLogger,
1633
+ })
1634
+ ).rejects.toBeInstanceOf(EtherscanAPIError)
1567
1635
  })
1568
1636
 
1569
1637
  describe('isPageFull and isDone', () => {
@@ -165,6 +165,58 @@ describe('EVM Family', () => {
165
165
  expect(gasOptions).toEqual(expectedGasOptions)
166
166
  })
167
167
 
168
+ it('should request and return EIP-1559 gas options on Avalanche C-Chain', async () => {
169
+ const gasOptions: GasOptions = await getGasOptions({
170
+ config: createMockEvmConfigInfo({
171
+ chainId: 43114,
172
+ node: mkLedgerNode({ explorerId: 'avax' }),
173
+ gasTracker: mkLedgerGasTracker({ explorerId: 'avax' }),
174
+ eip1559BaseFeeMultiplier: 2,
175
+ }),
176
+ options: { useEIP1559: true },
177
+ })
178
+
179
+ expect(mockedNetwork).toHaveBeenCalledWith(
180
+ expect.objectContaining({
181
+ url: expect.stringMatching(/\/avax\/gastracker\/barometer\?display=eip1559$/),
182
+ })
183
+ )
184
+ expect(gasOptions.medium).toEqual({
185
+ maxFeePerGas: new BigNumber(10),
186
+ maxPriorityFeePerGas: new BigNumber(2),
187
+ gasPrice: null,
188
+ nextBaseFee: new BigNumber(4),
189
+ })
190
+ })
191
+
192
+ it('should request and return EIP-1559 gas options on BSC, whose base fee is zero', async () => {
193
+ mockedNetwork.mockReset()
194
+ mockedNetwork.mockReturnValueOnce(
195
+ makeNetworkResponse({ low: '1', medium: '2', high: '3', next_base: '0' })
196
+ )
197
+
198
+ const gasOptions: GasOptions = await getGasOptions({
199
+ config: createMockEvmConfigInfo({
200
+ chainId: 56,
201
+ node: mkLedgerNode({ explorerId: 'bnb' }),
202
+ gasTracker: mkLedgerGasTracker({ explorerId: 'bnb' }),
203
+ }),
204
+ options: { useEIP1559: true },
205
+ })
206
+
207
+ expect(mockedNetwork).toHaveBeenCalledWith(
208
+ expect.objectContaining({
209
+ url: expect.stringMatching(/\/bnb\/gastracker\/barometer\?display=eip1559$/),
210
+ })
211
+ )
212
+ expect(gasOptions.medium).toEqual({
213
+ maxFeePerGas: new BigNumber(2),
214
+ maxPriorityFeePerGas: new BigNumber(2),
215
+ gasPrice: null,
216
+ nextBaseFee: new BigNumber(0),
217
+ })
218
+ })
219
+
168
220
  it('should return legacy gas options when EIP-1559 not supported by gas tracker', async () => {
169
221
  const gasOptions: GasOptions = await getGasOptions({
170
222
  config: createMockEvmConfigInfo({
@@ -662,6 +662,60 @@ describe('EVM Family', () => {
662
662
  ])
663
663
  })
664
664
 
665
+ it('does not duplicate WFLR Deposit when equivalent Transfer mint is emitted', () => {
666
+ const wflr = '0x1D80c49BbBCd1C0911346656B529DF9E5c2F783d'
667
+ const recipient = '0x000000000000000000000000bebcf96eeed98d495f45407ce7017179738e3552'
668
+ const amount = '0x000000000000000000000000000000000000000000000000000000000000002a'
669
+ const result = parseERC20TransfersFromLogs(
670
+ [
671
+ { address: wflr, topics: [WETH_DEPOSIT_TOPIC, recipient], data: amount },
672
+ {
673
+ address: wflr,
674
+ topics: [TRANSFER_TOPIC, `0x${'0'.repeat(24)}${'0'.repeat(40)}`, recipient],
675
+ data: amount,
676
+ },
677
+ ],
678
+ testLogger
679
+ )
680
+
681
+ expect(result).toEqual([
682
+ {
683
+ asset: { type: 'erc20', assetReference: wflr },
684
+ from: '0x0000000000000000000000000000000000000000',
685
+ to: '0xbeBcf96eEEd98D495F45407CE7017179738E3552',
686
+ value: '42',
687
+ },
688
+ ])
689
+ })
690
+ it('does not duplicate WETH-style Withdrawal when equivalent Transfer burn is emitted', () => {
691
+ const wrappedNative = '0x1111111111111111111111111111111111111111'
692
+ const owner = '0x000000000000000000000000bebcf96eeed98d495f45407ce7017179738e3552'
693
+ const amount = '0x000000000000000000000000000000000000000000000000000000000000002a'
694
+ const result = parseERC20TransfersFromLogs(
695
+ [
696
+ {
697
+ address: wrappedNative,
698
+ topics: ['0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65', owner],
699
+ data: amount,
700
+ },
701
+ {
702
+ address: wrappedNative,
703
+ topics: [TRANSFER_TOPIC, owner, `0x${'0'.repeat(64)}`],
704
+ data: amount,
705
+ },
706
+ ],
707
+ testLogger
708
+ )
709
+
710
+ expect(result).toEqual([
711
+ {
712
+ asset: { type: 'erc20', assetReference: wrappedNative },
713
+ from: '0xbeBcf96eEEd98D495F45407CE7017179738E3552',
714
+ to: '0x0000000000000000000000000000000000000000',
715
+ value: '42',
716
+ },
717
+ ])
718
+ })
665
719
  it('parses Mint as Transfer from 0x0', () => {
666
720
  const MINT_TOPIC = '0x0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885'
667
721
  const L2_BASE_TOKEN = '0x000000000000000000000000000000000000800A'
@@ -1929,8 +1983,8 @@ describe('EVM Family', () => {
1929
1983
 
1930
1984
  describe('getTokenBalance', () => {
1931
1985
  it('should call contract with normalized addresses for both account and token', async () => {
1932
- const EIP1191_TOKEN_ADDRESS = '0xaBf26902Fd7B624e0db40D31171eA9ddDf078351'
1933
- const NORMALIZED_TOKEN_ADDRESS = '0xabf26902fd7b624e0db40d31171ea9dddf078351'
1986
+ const EIP1191_ERC20_ADDRESS = '0xaBf26902Fd7B624e0db40D31171eA9ddDf078351'
1987
+ const NORMALIZED_ERC20_ADDRESS = '0xabf26902fd7b624e0db40d31171ea9dddf078351'
1934
1988
 
1935
1989
  // The balanceOf call is made via Contract.call which internally uses _perform
1936
1990
  // We need to check that the Contract is constructed with the normalized address
@@ -1938,13 +1992,13 @@ describe('EVM Family', () => {
1938
1992
  .spyOn(JsonRpcProvider.prototype, 'call')
1939
1993
  .mockResolvedValue('0x0000000000000000000000000000000000000000000000000000000000000064')
1940
1994
 
1941
- await nodeApi.getTokenBalance(EIP1191_CHECKSUMMED_ADDRESS, EIP1191_TOKEN_ADDRESS)
1995
+ await nodeApi.getTokenBalance(EIP1191_CHECKSUMMED_ADDRESS, EIP1191_ERC20_ADDRESS)
1942
1996
 
1943
1997
  // The call should be made to the normalized contract address
1944
1998
  // and the data should contain the normalized account address
1945
1999
  expect(callSpy).toHaveBeenCalledWith(
1946
2000
  expect.objectContaining({
1947
- to: NORMALIZED_TOKEN_ADDRESS,
2001
+ to: NORMALIZED_ERC20_ADDRESS,
1948
2002
  // The data contains the function selector (0x70a08231) + padded address
1949
2003
  data: expect.stringContaining(NORMALIZED_ADDRESS.slice(2)),
1950
2004
  })
package/.oxlintrc.json DELETED
@@ -1,94 +0,0 @@
1
- {
2
- "$schema": "../../../node_modules/oxlint/configuration_schema.json",
3
- "extends": ["../.oxlintrc.json"],
4
- "rules": {
5
- "typescript/explicit-function-return-type": "error"
6
- },
7
- "overrides": [
8
- {
9
- "files": ["src/api/index.ts"],
10
- "rules": {
11
- "eslint/no-restricted-imports": [
12
- "warn",
13
- {
14
- "patterns": [
15
- {
16
- "regex": "^(\\.\\./)+(network)(/|\\.[cm]?[jt]s$|$)",
17
- "message": "ADR-049: api/ may only import logic/, types/, config.ts, errors.ts"
18
- }
19
- ]
20
- }
21
- ]
22
- }
23
- },
24
- {
25
- "files": [
26
- "src/network/explorer/types.ts",
27
- "src/network/node/explorerProxy.ts",
28
- "src/network/node/gethCallTracerToTraceBlockItems.ts",
29
- "src/network/node/rpc.common.ts"
30
- ],
31
- "rules": {
32
- "eslint/no-restricted-imports": [
33
- "warn",
34
- {
35
- "patterns": [
36
- {
37
- "regex": "^(\\.\\./)+(api|logic)(/|\\.[cm]?[jt]s$|$)",
38
- "message": "ADR-049: network/ may only import types/, config.ts, errors.ts"
39
- }
40
- ]
41
- }
42
- ]
43
- }
44
- },
45
- {
46
- "files": ["src/types/staking.ts"],
47
- "rules": {
48
- "eslint/no-restricted-imports": [
49
- "warn",
50
- {
51
- "patterns": [
52
- {
53
- "regex": "^(\\.\\./)+(api|logic|network|config|errors)(/|\\.[cm]?[jt]s$|$)",
54
- "message": "ADR-049: types/ may not import any other layer"
55
- }
56
- ]
57
- }
58
- ]
59
- }
60
- },
61
- {
62
- "files": ["src/config.ts"],
63
- "rules": {
64
- "eslint/no-restricted-imports": [
65
- "warn",
66
- {
67
- "patterns": [
68
- {
69
- "regex": "^\\.{1,2}/",
70
- "message": "ADR-049: config.ts and errors.ts may not import any other file"
71
- }
72
- ]
73
- }
74
- ]
75
- }
76
- },
77
- {
78
- "files": ["**/*.test.ts", "**/tests/**"],
79
- "rules": {
80
- "eslint/no-restricted-imports": "off"
81
- }
82
- },
83
- {
84
- "files": ["src/**/*.fixtures.ts", "src/**/*.test.ts"],
85
- "env": {
86
- "jest": true
87
- },
88
- "plugins": ["jest"],
89
- "rules": {
90
- "typescript/explicit-function-return-type": "off"
91
- }
92
- }
93
- ]
94
- }
package/docs/abis.md DELETED
@@ -1,20 +0,0 @@
1
- # `abis`
2
- The contract Application Binary Interface (ABI) is the standard way to interact with smart contracts in the Ethereum ecosystem. This JSON file represents the various methods and properties of a smart contract and is essential for crafting the calldata necessary to interact with it.
3
-
4
- ## Files
5
-
6
- #### erc20.abi.json
7
- Defines the API for a fungible token (ERC20).
8
- Full definition of the interface: https://docs.openzeppelin.com/contracts/4.x/api/token/erc20
9
-
10
- #### erc721.abi.json
11
- Defines the API for a non-fungible token (NFT) (ERC721).
12
- Full definition of the interface: https://docs.openzeppelin.com/contracts/4.x/api/token/erc721
13
-
14
- #### erc1155.abi.json
15
- Defines the API for a semi-fungible token (NFT) (ERC1155).
16
- Full definition of the interface: https://docs.openzeppelin.com/contracts/4.x/api/token/erc1155
17
-
18
- #### optimismGasPriceOracle.abi.json
19
- Specifies the API for the Optimism oracle smart contract dedicated to returning the pricing of transaction data availability on the L1 (Ethereum).
20
- See documentation here: https://docs.optimism.io/builders/dapp-developers/transactions/estimates (section "Estimate the L1 data fee")
package/docs/adapters.md DELETED
@@ -1,10 +0,0 @@
1
- # `adapters`
2
- Set of functions in charge of converting a transaction format specific to a library or a backend into a Ledger Live format or vice-versa.
3
-
4
- ## Files
5
-
6
- #### etherscan.ts
7
- Functions used to convert transactions coming from the [etherscan-like explorers](https://docs.etherscan.io/api-endpoints/accounts)
8
-
9
- #### ledger.ts
10
- Functions used to convert transactions coming from the [Ledger explorers](https://explorers.api.live.ledger.com/blockchain/v4/eth/docs/#/address/Transactions%20by%20address)
@@ -1,102 +0,0 @@
1
- # EVM family integration process
2
-
3
- _How to integrate a new EVM family currency in the Ledger Live application._
4
-
5
- This document will outline the different steps needed to implement a new EVM family currency in the Ledger Live application.
6
- Depending on the specifications, some steps might not be needed for all currencies.
7
-
8
- ## Specifications
9
-
10
- Most EVM coin integrations are quite similar. The main specs will be outlined below.
11
- But each coin may have its specificities and more information can be found on the specific coin integration Jira Epic created for each integration, based on this template https://ledgerhq.atlassian.net/browse/LIVE-10187
12
-
13
- - Integration is done in Ledger Live desktop and Ledger Live mobile
14
- - Supported features:
15
- - Sending and receiving coins
16
- - Viewing transaction history
17
- - Token support, enabling interactions with the blockchain tokens
18
- - Use of public RPC node and explorer (etherscan-like). This should be specified in the corresponding Jira Epic
19
- - To find a public node, you can use https://chainlist.org/ for example
20
- - To find a public explorer, you can use https://blockscan.com/ (etherscan-like) for example
21
- - The [Ethereum embedded app](https://github.com/LedgerHQ/app-ethereum) must handle this new network
22
-
23
- ## Live codebase update
24
-
25
- Here is an example PR of an EVM currency integration: https://github.com/LedgerHQ/ledger-live/pull/4008
26
-
27
- ### Main steps
28
-
29
- _Common steps for all new EVM currency integration_
30
-
31
- 1. Add a new config entry for the new currency in the `@domain/entity-currency-crypto` registry
32
- 2. Nothing to do for the fee-estimation dummy recipient: the dead address used for fee estimation is now owned by the consumer (e.g. ledger-live-common's EVM family, `libs/ledger-live-common/src/families/evm/constants.ts`) and covers every EVM currency (only zkSync differs). `coin-evm` no longer ships a `getEvmDummyAddress` helper.
33
- 3. Add the new currency ID to the `setSupportedCurrencies` function param on each relevant project ([CLI](../../../../../apps/cli/src/live-common-setup-base.ts), [LLD](../../../../../apps/ledger-live-desktop/src/live-common-set-supported-currencies.ts), [LLM](../../../../../apps/ledger-live-mobile/src/live-common-setup.ts), [LLC test environment](../../../../../libs/ledger-live-common/src/__tests__/test-helpers/environment.ts), [web-tools](../../../../../apps/web-tools/src/live-common-setup.ts) and [account-migration tests](../../../../../libs/ledger-live-common/src/__tests__/migration/account-migration.ts))
34
- 4. Add a new feature flag config for this currency:
35
- 1. The new feature flag type in the [`CurrencyFeatures`](../../../../../libs/types-live/src/feature.ts) type under `libs/types-live/src/feature.ts`
36
- 2. The new feature flag definition with default value in the [`CURRENCY_DEFAULT_FEATURES`](../../../../../libs/ledger-live-common/src/featureFlags/defaultFeatures.ts) mapping under `libs/ledger-live-common/src/featureFlags/defaultFeatures.ts`
37
- 3. Use this new feature flag in [`useCurrenciesUnderFeatureFlag.ts`](../../../../../libs/ledger-live-common/src/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.ts)
38
- 5. Add the EVM config for RPC node and explorer under [`libs/ledger-live-common/src/families/evm/config.ts`](../../../../../libs/ledger-live-common/src/families/evm/config.ts)
39
- 6. Update snapshot files:
40
- 1. `pnpm test -- -u` from `libs/coin-framework` to update `formatCurrencyUnit.test.ts` snapshots
41
- 2. `pnpm test:playwright tests/specs/services/wallet-api.spec.ts` from `apps/ledger-live-desktop` and update `tests/fixtures/wallet-api.ts` with new currencies
42
- 7. Add the related currency icon to the [crypto-icons](https://github.com/LedgerHQ/crypto-icons) repository (see its README for instructions)
43
-
44
- ### Optional steps
45
-
46
- _Optional / extra steps that might be needed on a case-by-case basis depending on the integration_
47
-
48
- - If the related currency public explorer is not an etherscan-like, you might need to add a new implementation for this currency explorer
49
- - If needed, create a new explorer implementation of this explorer API in a new file under the [`libs/coin-modules/coin-evm/src/network/explorer`](../../src/network/explorer) folder
50
- - Add the new explorer type to:
51
- - the `getExplorerApi` function under [`libs/coin-modules/coin-evm/src/network/explorer/index.ts`](../../src/network/explorer/index.ts)
52
- - the `EthereumLikeInfo.explorer.type` type under [`libs/ledger-wallet-framework/src/types.ts`](../../../../../libs/ledger-wallet-framework/src/types.ts)
53
- - if the new explorer type follows the etherscan-like API, add it to the `isEtherscanLikeExplorerConfig` type guard under [`libs/coin-modules/coin-evm/src/network/explorer/types.ts`](../../src/network/explorer/types.ts) (this is the case for some custom made explorers that are not blockscan white label implementation, but are still compatible with the blockscan/etherscan API)
54
-
55
- ## Tokens support
56
-
57
- Here are the steps to handle the new currencies (ERC20) tokens, if relevant:
58
-
59
- - add the new tokens config to the [CAL](https://github.com/LedgerHQ/crypto-assets) (historically handled by @adrienlacombe-ledger)
60
- - after this update of the CAL, check that the tokens are present on the CDN, replacing `{chainId}` with the actual currency chain ID, specified under `ethereumLikeInfo.chainId` in the currency config (in the `@domain/entity-currency-crypto` registry) which would be `1` for ethereum mainnet for example, using https://cdn.live.ledger.com/cryptoassets/evm/{chainId}/erc20.json
61
-
62
- No change should be needed on Ledger Live side since token data is consumed from
63
- CAL/CDN during the release flow.
64
-
65
- ## Counter values support (fiat prices)
66
-
67
- To have the associated market (fiat) price supported for the network being added, some config updates are needed on the `CAL` and `countervalue service` sides.
68
-
69
- The process for this can be found here: https://ledgerhq.atlassian.net/wiki/spaces/WALLETCO/pages/4354769042/Adding+price+support+for+a+currency
70
-
71
- ## Ethereum app firmware update
72
-
73
- The new network being added needs to be handled by the [nano ethereum app](https://github.com/LedgerHQ/app-ethereum).
74
-
75
- Make sure the network being added is present under the `network_info_t` mapping in `src_common/network.c` ([here](https://github.com/LedgerHQ/app-ethereum/blob/develop/src_common/network.c) for staging and [here](https://github.com/LedgerHQ/app-ethereum/blob/master/src_common/network.c) for prod).
76
-
77
- In Ledger Live, make sure the ethereum nano app version requirements match the latest version of the ethereum app handling the network being added:
78
-
79
- - `appVersion` in `getAppQuery` under [`libs/coin-modules/coin-evm/src/specs.ts`](../../../../ledger-live-common/src/families/evm/bot/specs.ts)
80
- - `Ethereum` in `appVersionsRequired` under [`libs/ledger-live-common/src/apps/support.ts`](../../../../../libs/ledger-live-common/src/apps/support.ts)
81
- - related tests for the ethereum app version under [`libs/ledger-live-common/src/apps/support.test.ts`](../../../../../libs/ledger-live-common/src/apps/support.test.ts)
82
-
83
- ## Tests
84
-
85
- ### Bot
86
-
87
- - Make sure to fund the appropriate bot(s) with coins and tokens of the new network being added. For local portfolio bot context, see [`libs/ledger-live-common/src/bot/portfolio/README.md`](../../../../../libs/ledger-live-common/src/bot/portfolio/README.md).
88
- - Make sure to make the bot run multiple times on your PR to make sure everything works fine with the new network
89
- - If the coin related to the network you are adding is somewhat expensive, you can tailor the minimum balance needed to test this coin by updating `minBalancePerCurrencyId` under [`libs/coin-modules/coin-evm/src/specs.ts`](../../../../ledger-live-common/src/families/evm/bot/specs.ts)
90
-
91
- ### Manual testing
92
-
93
- The bare minimum to test in terms of flows is, on both LLD and LLM:
94
-
95
- - Add account
96
- - Send funds (coins) from one account to another
97
- - Add (receive) token (if supported)
98
- - Send token (if supported)
99
-
100
- ## Firebase Feature Flag config
101
-
102
- Make sure to add the newly created currency feature flag to the Firebase config