@exodus/ethereum-api 8.14.0 → 8.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,24 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [8.16.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.15.0...@exodus/ethereum-api@8.16.0) (2024-08-27)
7
+
8
+
9
+ ### Features
10
+
11
+ * allow addEthereumChain custom fee data ([#3293](https://github.com/ExodusMovement/assets/issues/3293)) ([824b585](https://github.com/ExodusMovement/assets/commit/824b585c8101b8c5bb50e236f18d33e5e5cadc90))
12
+
13
+
14
+
15
+ ## [8.15.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.14.0...@exodus/ethereum-api@8.15.0) (2024-08-27)
16
+
17
+
18
+ ### Features
19
+
20
+ * introduce Clarity V2 server ([#2982](https://github.com/ExodusMovement/assets/issues/2982)) ([90ebbf0](https://github.com/ExodusMovement/assets/commit/90ebbf0b48c118c1aa50f1b8adb4c941c3344f1b))
21
+
22
+
23
+
6
24
  ## [8.14.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.13.3...@exodus/ethereum-api@8.14.0) (2024-08-26)
7
25
 
8
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "8.14.0",
3
+ "version": "8.16.0",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -32,7 +32,6 @@
32
32
  "@exodus/ethereumholesky-meta": "^1.0.3",
33
33
  "@exodus/ethereumjs-util": "^7.1.0-exodus.7",
34
34
  "@exodus/fetch": "^1.3.0",
35
- "@exodus/key-utils": "^3.1.0",
36
35
  "@exodus/models": "^11.0.0",
37
36
  "@exodus/simple-retry": "^0.0.6",
38
37
  "@exodus/solidity-contract": "^1.1.3",
@@ -65,5 +64,5 @@
65
64
  "type": "git",
66
65
  "url": "git+https://github.com/ExodusMovement/assets.git"
67
66
  },
68
- "gitHead": "12dda1cbba91cbfeaeb0811570baa671b8557c2c"
67
+ "gitHead": "acd3513f5e5defeb1a1e181a4655f431e1b1289f"
69
68
  }
@@ -160,6 +160,7 @@ export const fromAddEthereumChainParameterToFactoryParams = (params) => {
160
160
  isTestnet: params.isTestnet,
161
161
  ...params.plugin, // extra plugin configuration
162
162
  },
163
+ feeData: params.feeData,
163
164
  baseFeePerGas: params.baseFeePerGas,
164
165
  gasPrice: params.gasPrice,
165
166
  eip1559Enabled: params.eip1559Enabled,
@@ -1,6 +1,6 @@
1
1
  import { connectAssetsList } from '@exodus/assets'
2
2
  import { pick } from '@exodus/basic-utils'
3
- import bip44Constants from '@exodus/bip44-constants/by-ticker'
3
+ import bip44Constants from '@exodus/bip44-constants/by-ticker.js'
4
4
  import {
5
5
  createEthereumLikeAccountState,
6
6
  createGetKeyIdentifier as defaultCreateGetKeyIdentifier,
@@ -161,6 +161,7 @@ export const createAssetFactory = ({
161
161
  let monitor
162
162
  switch (monitorType) {
163
163
  case 'clarity':
164
+ case 'clarity-v2':
164
165
  monitor = new ClarityMonitor({
165
166
  assetClientInterface,
166
167
  interval: ms(monitorInterval || '5m'),
@@ -0,0 +1,90 @@
1
+ import { fetch } from '@exodus/fetch'
2
+ import { retry } from '@exodus/simple-retry'
3
+
4
+ import ClarityServer from './clarity'
5
+
6
+ const getTextFromResponse = async (response) => {
7
+ try {
8
+ const responseBody = await response.text()
9
+ return responseBody.slice(0, 100)
10
+ } catch {
11
+ return ''
12
+ }
13
+ }
14
+
15
+ const fetchJson = async (url, fetchOptions) => {
16
+ const response = await fetch(url, fetchOptions)
17
+
18
+ if (!response.ok)
19
+ throw new Error(
20
+ `${url} returned ${response.status}: ${
21
+ response.statusText || 'Unknown Status Text'
22
+ }. Body: ${await getTextFromResponse(response)}`
23
+ )
24
+ return response.json()
25
+ }
26
+
27
+ async function fetchJsonRetry(url, fetchOptions) {
28
+ const waitTimes = ['3s']
29
+ const fetchWithRetry = retry(fetchJson, { delayTimesMs: waitTimes })
30
+ return fetchWithRetry(url, fetchOptions)
31
+ }
32
+
33
+ export default class ClarityServerV2 extends ClarityServer {
34
+ constructor({ baseAssetName, uri }) {
35
+ super({ baseAssetName, uri })
36
+ this.baseApiPath = this.uri + `/api/v2/${this.baseAssetName}`
37
+ }
38
+
39
+ async getAllTransactions({ address, cursor }) {
40
+ let { blockNumber } = this.#decodeCursor(cursor)
41
+ blockNumber = blockNumber.toString()
42
+
43
+ const transactions = []
44
+
45
+ while (true) {
46
+ const url = new URL(`${this.baseApiPath}/addresses/${address}/transactions`)
47
+ url.searchParams.set('cursor', blockNumber)
48
+ url.searchParams.set('withInput', 'true')
49
+
50
+ const { transactions: txs, cursor: nextBlockNumber } = await fetchJsonRetry(url)
51
+
52
+ if (txs.length === 0) {
53
+ // fetch until no more new transactions
54
+ blockNumber = nextBlockNumber
55
+ break
56
+ }
57
+
58
+ if (nextBlockNumber <= blockNumber) {
59
+ console.warn('Invalid cursor: next block number is not greater than current block number')
60
+ }
61
+
62
+ transactions.push(...txs)
63
+ blockNumber = nextBlockNumber
64
+ }
65
+
66
+ const newCursor = Buffer.alloc(8)
67
+ newCursor.writeBigUInt64LE(BigInt(blockNumber), 0)
68
+
69
+ return {
70
+ transactions: {
71
+ confirmed: transactions,
72
+ pending: [],
73
+ },
74
+ cursor: newCursor,
75
+ }
76
+ }
77
+
78
+ #decodeCursor(cursor) {
79
+ if (Buffer.isBuffer(cursor)) {
80
+ // New format: buffer containing only the block number
81
+ if (cursor.length === 8) return { blockNumber: cursor.readBigUInt64LE(0) }
82
+
83
+ // Old format: buffer with length 26
84
+ if (cursor.length === 26) return { blockNumber: cursor.readBigInt64LE(10) }
85
+ }
86
+
87
+ // Doesn't match any known format, return default
88
+ return { blockNumber: BigInt(0) }
89
+ }
90
+ }
@@ -11,6 +11,7 @@ import assert from 'minimalistic-assert'
11
11
  import { create } from './api'
12
12
  import ApiCoinNodesServer from './api-coin-nodes'
13
13
  import ClarityServer from './clarity'
14
+ import ClarityServerV2 from './clarity-v2'
14
15
 
15
16
  export function createEvmServer({ assetName, serverUrl, monitorType }) {
16
17
  assert(assetName, 'assetName is required')
@@ -21,6 +22,8 @@ export function createEvmServer({ assetName, serverUrl, monitorType }) {
21
22
  return new ApiCoinNodesServer({ uri: serverUrl })
22
23
  case 'clarity':
23
24
  return new ClarityServer({ baseAssetName: assetName, uri: serverUrl })
25
+ case 'clarity-v2':
26
+ return new ClarityServerV2({ baseAssetName: assetName, uri: serverUrl })
24
27
  case 'magnifier':
25
28
  return create(serverUrl, assetName)
26
29
  default:
@@ -1,21 +1,2 @@
1
- /**
2
- * This is a "light" version of @exodus/core resolution to select the native WebSocket on BE
3
- * It's a workaround until https://github.com/ExodusMovement/assets/pull/72 is merged.
4
- *
5
- * Based on https://github.com/ExodusMovement/fetch/blob/master/core.js , note that chooses native on Desktop
6
- */
7
- if (typeof process !== 'undefined' && (process.type === 'renderer' || process.type === 'worker')) {
8
- // THIS IS FOR DESKTOP
9
- if (process.env.EXODUS_DISABLE_WS) {
10
- module.exports = globalThis.WebSocket
11
- } else {
12
- module.exports = require('ws')
13
- }
14
- // eslint-disable-next-line no-undef
15
- } else if (typeof WebSocket === 'undefined') {
16
- // THIS IS FOR UNIT TESTING.
17
- module.exports = require('ws')
18
- } else {
19
- // THIS IS FOR BE
20
- module.exports = globalThis.WebSocket
21
- }
1
+ // Uses cjs to optimize out requiring / bundling ws
2
+ export { default } from './websocket.cjs'
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This is a "light" version of @exodus/core resolution to select the native WebSocket on BE
3
+ * It's a workaround until https://github.com/ExodusMovement/assets/pull/72 is merged.
4
+ *
5
+ * Based on https://github.com/ExodusMovement/fetch/blob/master/core.js , note that chooses native on Desktop
6
+ */
7
+ if (typeof process !== 'undefined' && (process.type === 'renderer' || process.type === 'worker')) {
8
+ // THIS IS FOR DESKTOP
9
+ if (process.env.EXODUS_DISABLE_WS) {
10
+ module.exports = globalThis.WebSocket
11
+ } else {
12
+ module.exports = require('ws')
13
+ }
14
+ // eslint-disable-next-line no-undef
15
+ } else if (typeof WebSocket === 'undefined') {
16
+ // THIS IS FOR UNIT TESTING.
17
+ module.exports = require('ws')
18
+ } else {
19
+ // THIS IS FOR BE
20
+ module.exports = globalThis.WebSocket
21
+ }