@exodus/ethereum-api 6.2.6 → 6.2.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "6.2.6",
3
+ "version": "6.2.7",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -36,5 +36,5 @@
36
36
  "devDependencies": {
37
37
  "@exodus/models": "^8.10.4"
38
38
  },
39
- "gitHead": "267d6f4bdfeb19fc7cd060b67083ca45437e9bfd"
39
+ "gitHead": "946100ffe13a706d3aed1a94f59fd36bd385491d"
40
40
  }
@@ -143,6 +143,9 @@ export default class ApiCoinNodesServer extends EventEmitter {
143
143
  return this.sendRequest(request)
144
144
  }
145
145
 
146
+ // for fee monitor
147
+ getGasPrice = this.gasPrice
148
+
146
149
  async estimateGas(...params) {
147
150
  const request = this.estimateGasRequest(...params)
148
151
  return this.sendRequest(request)
@@ -197,4 +200,8 @@ export default class ApiCoinNodesServer extends EventEmitter {
197
200
  const request = this.simulateRawTransactionRequest(...params)
198
201
  return this.sendRequest(request)
199
202
  }
203
+
204
+ stop() {
205
+ // no web socket to stop!
206
+ }
200
207
  }
@@ -118,6 +118,11 @@ export function create(defaultURL, ensAssetName) {
118
118
  return requestWithRetry('proxy', { method: 'eth_gasPrice' })
119
119
  },
120
120
 
121
+ // for fee monitor
122
+ async getGasPrice() {
123
+ return requestWithRetry('proxy', { method: 'eth_gasPrice' })
124
+ },
125
+
121
126
  async getTransactionCount(address, tag = 'latest') {
122
127
  return requestWithRetry('proxy', { method: 'eth_getTransactionCount', address, tag })
123
128
  },
@@ -130,6 +130,12 @@ export default class ClarityServer extends EventEmitter {
130
130
  })
131
131
  }
132
132
 
133
+ // for fee monitors
134
+ async getGasPrice() {
135
+ const fee = await this.getFee()
136
+ return fee?.gasPrice
137
+ }
138
+
133
139
  async sendRpcRequest(rpcRequest) {
134
140
  const rpcSocket = this.connectRpc()
135
141
  return new Promise((resolve, reject) => {
@@ -393,4 +399,8 @@ export default class ClarityServer extends EventEmitter {
393
399
  formatFeeNamespace() {
394
400
  return `${this.baseNamespace}/fee`
395
401
  }
402
+
403
+ stop() {
404
+ this.dispose()
405
+ }
396
406
  }
@@ -3,12 +3,15 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'avalanchec'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class AvalancheFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee }) {
9
+ const server = getServerByName(assetName)
10
+ const getGasPrice = (...args) => server.gasPrice(...args)
8
11
  super({
9
12
  updateFee,
10
13
  assetName,
11
- getGasPrice: getServerByName(assetName).gasPrice,
14
+ getGasPrice,
12
15
  })
13
16
  }
14
17
  }
@@ -3,12 +3,15 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'bsc'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class BscFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee }) {
9
+ const server = getServerByName(assetName)
10
+ const getGasPrice = (...args) => server.gasPrice(...args)
8
11
  super({
9
12
  updateFee,
10
13
  assetName,
11
- getGasPrice: getServerByName(assetName).gasPrice,
14
+ getGasPrice,
12
15
  })
13
16
  }
14
17
  }
@@ -3,12 +3,15 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'ethereum'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class EthereumFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee, interval }) {
9
+ const server = getServerByName(assetName)
10
+ const getGasPrice = (...args) => server.gasPrice(...args)
8
11
  super({
9
12
  updateFee,
10
13
  assetName,
11
- getGasPrice: getServerByName(assetName).gasPrice,
14
+ getGasPrice,
12
15
  interval,
13
16
  })
14
17
  }
@@ -3,6 +3,7 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'ethereumarbnova'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class EthereumArbnovaFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee, interval }) {
8
9
  super({
@@ -3,6 +3,7 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'ethereumarbone'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class EthereumArboneFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee, interval }) {
8
9
  super({
@@ -3,12 +3,15 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'ethereumclassic'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class EthereumClassicFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee }) {
9
+ const server = getServerByName(assetName)
10
+ const getGasPrice = (...args) => server.gasPrice(...args)
8
11
  super({
9
12
  updateFee,
10
13
  assetName,
11
- getGasPrice: getServerByName(assetName).gasPrice,
14
+ getGasPrice,
12
15
  })
13
16
  }
14
17
  }
@@ -3,12 +3,15 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'ethereumgoerli'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class EthereumGoerliFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee, interval }) {
9
+ const server = getServerByName(assetName)
10
+ const getGasPrice = (...args) => server.gasPrice(...args)
8
11
  super({
9
12
  updateFee,
10
13
  assetName,
11
- getGasPrice: getServerByName(assetName).gasPrice,
14
+ getGasPrice,
12
15
  interval,
13
16
  })
14
17
  }
@@ -3,12 +3,15 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'fantommainnet'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class FantomFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee }) {
9
+ const server = getServerByName(assetName)
10
+ const getGasPrice = (...args) => server.gasPrice(...args)
8
11
  super({
9
12
  updateFee,
10
13
  assetName,
11
- getGasPrice: getServerByName(assetName).gasPrice,
14
+ getGasPrice,
12
15
  })
13
16
  }
14
17
  }
@@ -3,12 +3,15 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'harmonymainnet'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class HarmonyFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee }) {
9
+ const server = getServerByName(assetName)
10
+ const getGasPrice = (...args) => server.gasPrice(...args)
8
11
  super({
9
12
  updateFee,
10
13
  assetName,
11
- getGasPrice: getServerByName(assetName).gasPrice,
14
+ getGasPrice,
12
15
  })
13
16
  }
14
17
  }
@@ -1,3 +1,5 @@
1
+ export * from './server-based-fee-monitor'
2
+
1
3
  export * from './ethereum'
2
4
  export * from './ethereumclassic'
3
5
  export * from './ethereumgoerli'
@@ -3,6 +3,7 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'optimism'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class OptimismFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee, interval }) {
8
9
  super({
@@ -3,12 +3,15 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'matic'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class PolygonFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee }) {
9
+ const server = getServerByName(assetName)
10
+ const getGasPrice = (...args) => server.gasPrice(...args)
8
11
  super({
9
12
  updateFee,
10
13
  assetName,
11
- getGasPrice: getServerByName(assetName).gasPrice,
14
+ getGasPrice,
12
15
  })
13
16
  }
14
17
  }
@@ -3,12 +3,15 @@ import { getServerByName } from '../exodus-eth-server'
3
3
 
4
4
  const assetName = 'rootstock'
5
5
 
6
+ // @deprecated use ./server-based-fee-monitor.js
6
7
  export class RootstockFeeMonitor extends EthereumLikeFeeMonitor {
7
8
  constructor({ updateFee }) {
9
+ const server = getServerByName(assetName)
10
+ const getGasPrice = (...args) => server.gasPrice(...args)
8
11
  super({
9
12
  updateFee,
10
13
  assetName,
11
- getGasPrice: getServerByName(assetName).gasPrice,
14
+ getGasPrice,
12
15
  })
13
16
  }
14
17
  }
@@ -0,0 +1,39 @@
1
+ import { EthereumLikeFeeMonitor } from '@exodus/ethereum-lib'
2
+ import assert from 'minimalistic-assert'
3
+ import { getServerByName } from '../exodus-eth-server'
4
+
5
+ /**
6
+ * Generic eth server based fee monitor.
7
+ *
8
+ * Compatible with all servers, clarity, magnifier and api-coin (they all implement the gasPrice method).
9
+ *
10
+ * Usage in the index files:
11
+ *
12
+ * const api = {
13
+ * ...
14
+ * createFeeMonitor: serverBasedFeeMonitorFactoryFactory({ interval: '50s', assetName: base.name }),
15
+ * ...
16
+ * }
17
+ */
18
+
19
+ export const serverBasedFeeMonitorFactoryFactory = ({ assetName, interval }) => {
20
+ assert(assetName, 'assetName is required')
21
+
22
+ // NOTE: Using getServerByName for simplicity now but
23
+ // remove getServerByName and convert server to a param instead.
24
+ // This is to avoid global references, static creation, remove the chain specific map and allow IOC
25
+ const server = getServerByName(assetName)
26
+ const getGasPrice = (...args) => server.getGasPrice(...args)
27
+ const FeeMonitorClass = class ServerBaseEthereumFeeMonitor extends EthereumLikeFeeMonitor {
28
+ constructor({ updateFee }) {
29
+ assert(updateFee, 'updateFee is required')
30
+ super({
31
+ updateFee,
32
+ assetName,
33
+ getGasPrice,
34
+ interval,
35
+ })
36
+ }
37
+ }
38
+ return (...args) => new FeeMonitorClass(...args)
39
+ }