@exodus/ethereum-api 7.4.0 → 7.5.1

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": "7.4.0",
3
+ "version": "7.5.1",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -25,7 +25,7 @@
25
25
  "@exodus/bip44-constants": "^195.0.0",
26
26
  "@exodus/crypto": "^1.0.0-rc.0",
27
27
  "@exodus/currency": "^2.1.3",
28
- "@exodus/ethereum-lib": "^4.2.7",
28
+ "@exodus/ethereum-lib": "^4.8.1",
29
29
  "@exodus/ethereum-meta": "^1.2.0",
30
30
  "@exodus/ethereumholesky-meta": "^1.0.1",
31
31
  "@exodus/ethereumjs-util": "^7.1.0-exodus.7",
@@ -57,5 +57,5 @@
57
57
  "cross-fetch": "^3.1.5",
58
58
  "delay": "4.0.1"
59
59
  },
60
- "gitHead": "ac617aef893ac9d6b1689ca12e7b6de68a258621"
60
+ "gitHead": "220c00b21c6bf4d250aea7a40d37ceebb1716979"
61
61
  }
@@ -21,6 +21,7 @@ import {
21
21
  signUnsignedTxWithSigner,
22
22
  validate,
23
23
  signMessage,
24
+ signMessageWithSigner,
24
25
  signHardwareFactory,
25
26
  DEFAULT_FEE_MONITOR_INTERVAL,
26
27
  } from '@exodus/ethereum-lib'
@@ -34,7 +35,6 @@ import { getEffectiveGasPrice, getFeeFactory } from './get-fee'
34
35
  import { createEthereumHooks } from './hooks'
35
36
  import { createStakingApi } from './staking-api'
36
37
  import { txSendFactory } from './tx-send'
37
- import { signMessageWithSigner } from '@exodus/ethereum-lib/src/sign-message'
38
38
  import { serverBasedFeeMonitorFactoryFactory } from './fee-monitor'
39
39
  import { createGetBalanceForAddress } from './get-balance-for-address'
40
40
  import { estimateL1DataFeeFactory, getL1GetFeeFactory } from './optimism-gas'
@@ -116,6 +116,7 @@ export const createAssetFactory = ({
116
116
  const createFeeMonitor = serverBasedFeeMonitorFactoryFactory({
117
117
  assetName: base.name,
118
118
  interval: config.feeMonitorInterval || feeMonitorInterval || DEFAULT_FEE_MONITOR_INTERVAL,
119
+ eip1559Enabled: feeData.eip1559Enabled, // this is not updated via remote config. Should it be?
119
120
  })
120
121
 
121
122
  const features = {
@@ -160,6 +160,21 @@ export default class ApiCoinNodesServer extends EventEmitter {
160
160
  // for fee monitor
161
161
  getGasPrice = this.gasPrice
162
162
 
163
+ async getLatestBlock() {
164
+ const request = this.buildRequest({
165
+ method: 'eth_getBlockByNumber',
166
+ params: ['latest', false],
167
+ })
168
+ return this.sendRequest(request)
169
+ }
170
+
171
+ async getBaseFeePerGas() {
172
+ const response = await this.getLatestBlock()
173
+ if (response.baseFeePerGas) {
174
+ return fromHexToString(response.baseFeePerGas)
175
+ }
176
+ }
177
+
163
178
  async estimateGas(...params) {
164
179
  const request = this.estimateGasRequest(...params)
165
180
  return this.sendRequest(request)
@@ -126,6 +126,17 @@ export function create(defaultURL, ensAssetName) {
126
126
  return requestWithRetry('proxy', { method: 'eth_gasPrice' })
127
127
  },
128
128
 
129
+ async getLatestBlock() {
130
+ return this.getBlockByNumber('latest')
131
+ },
132
+
133
+ async getBaseFeePerGas() {
134
+ const response = await this.getLatestBlock()
135
+ if (response.baseFeePerGas) {
136
+ return fromHexToString(response.baseFeePerGas)
137
+ }
138
+ },
139
+
129
140
  async getTransactionCount(address, tag = 'latest') {
130
141
  return requestWithRetry('proxy', { method: 'eth_getTransactionCount', address, tag })
131
142
  },
@@ -366,6 +366,17 @@ export default class ClarityServer extends EventEmitter {
366
366
  return this.sendRequest(request)
367
367
  }
368
368
 
369
+ async getLatestBlock() {
370
+ return this.getBlockByNumber('latest')
371
+ }
372
+
373
+ async getBaseFeePerGas() {
374
+ const response = await this.getLatestBlock()
375
+ if (response.baseFeePerGas) {
376
+ return fromHexToString(response.baseFeePerGas)
377
+ }
378
+ }
379
+
369
380
  async getBlockByHash(...params) {
370
381
  const request = this.getBlockByHashRequest(...params)
371
382
  return this.sendRequest(request)
@@ -1,6 +1,8 @@
1
- import { EthereumLikeFeeMonitor } from '@exodus/ethereum-lib'
1
+ import { FeeMonitor } from '@exodus/asset-lib'
2
2
  import assert from 'minimalistic-assert'
3
3
  import { getServerByName } from '../exodus-eth-server'
4
+ import { DEFAULT_FEE_MONITOR_INTERVAL } from '@exodus/ethereum-lib'
5
+ import { fromHexToString } from '../number-utils'
4
6
 
5
7
  /**
6
8
  * Generic eth server based fee monitor.
@@ -16,24 +18,37 @@ import { getServerByName } from '../exodus-eth-server'
16
18
  * }
17
19
  */
18
20
 
19
- export const serverBasedFeeMonitorFactoryFactory = ({ assetName, interval }) => {
21
+ export const serverBasedFeeMonitorFactoryFactory = ({
22
+ assetName,
23
+ interval = DEFAULT_FEE_MONITOR_INTERVAL,
24
+ eip1559Enabled,
25
+ }) => {
20
26
  assert(assetName, 'assetName is required')
21
-
22
27
  // NOTE: Using getServerByName for simplicity now but
23
28
  // remove getServerByName and convert server to a param instead.
24
29
  // This is to avoid global references, static creation, remove the chain specific map and allow IOC
25
30
  const server = getServerByName(assetName)
26
- const getGasPrice = (...args) => server.getGasPrice(...args)
27
- const FeeMonitorClass = class ServerBaseEthereumFeeMonitor extends EthereumLikeFeeMonitor {
31
+
32
+ const FeeMonitorClass = class ServerBaseEthereumFeeMonitor extends FeeMonitor {
28
33
  constructor({ updateFee }) {
29
34
  assert(updateFee, 'updateFee is required')
30
35
  super({
31
36
  updateFee,
32
37
  assetName,
33
- getGasPrice,
34
38
  interval,
35
39
  })
36
40
  }
41
+
42
+ async fetchFee() {
43
+ const gasPrice = fromHexToString(await server.getGasPrice())
44
+
45
+ const baseFeePerGas = eip1559Enabled ? `${await server.getBaseFeePerGas()} wei` : undefined
46
+
47
+ return {
48
+ gasPrice: `${gasPrice} wei`,
49
+ baseFeePerGas,
50
+ }
51
+ }
37
52
  }
38
53
  return (...args) => new FeeMonitorClass(...args)
39
54
  }
@@ -32,7 +32,12 @@ const txSendFactory = ({ assetClientInterface }) => {
32
32
  const baseAsset = asset.baseAsset
33
33
  const feeOpts = { ...feeOpts_ }
34
34
  const assets = await assetClientInterface.getAssetsForNetwork({ baseAssetName: baseAsset.name })
35
- let eip1559Enabled = baseAsset.name === 'ethereum' // TODO: temp override, clean up use of eip1559Enabled flag and default to always true
35
+
36
+ // Using a default zero value to not break code relying on the `tx.feeAmount` property.
37
+ // For example, some exchange providers don't supply this.
38
+ if (!feeAmount) {
39
+ feeAmount = asset.baseAsset.currency.ZERO
40
+ }
36
41
 
37
42
  const fromAddress = await assetClientInterface.getReceiveAddress({
38
43
  assetName: baseAsset.name,
@@ -41,6 +46,12 @@ const txSendFactory = ({ assetClientInterface }) => {
41
46
 
42
47
  let nonceParam = _nonce
43
48
 
49
+ const feeData = await assetClientInterface.getFeeData({
50
+ assetName: baseAsset.name,
51
+ })
52
+
53
+ let eip1559Enabled = feeData.eip1559Enabled
54
+
44
55
  // `replacedTx` is always an ETH/ETC transaction (not a token)
45
56
  let replacedTx, replacedTokenTx
46
57
  if (bumpTxId) {
@@ -68,19 +79,17 @@ const txSendFactory = ({ assetClientInterface }) => {
68
79
  address = (replacedTokenTx || replacedTx).to
69
80
  amount = (replacedTokenTx || replacedTx).coinAmount.negate()
70
81
  feeOpts.gasLimit = replacedTx.data.gasLimit
71
- const { gasPrice: currentGasPrice, eip1559Enabled: _eip1559Enabled } =
72
- await assetClientInterface.getFeeData({
73
- assetName,
74
- })
82
+
83
+ const { gasPrice: currentGasPrice } = feeData
75
84
  const { bumpedGasPrice, bumpedTipGasPrice } = calculateBumpedGasPrice({
76
85
  baseAsset,
77
86
  tx: replacedTx,
78
87
  currentGasPrice,
79
- eip1559Enabled: _eip1559Enabled,
88
+ eip1559Enabled,
80
89
  })
81
90
  feeOpts.gasPrice = bumpedGasPrice
82
91
  feeOpts.tipGasPrice = bumpedTipGasPrice
83
- eip1559Enabled = _eip1559Enabled && feeOpts.tipGasPrice
92
+ eip1559Enabled = feeData.eip1559Enabled && feeOpts.tipGasPrice
84
93
  nonceParam = replacedTx.data.nonce
85
94
  txInput = replacedTokenTx ? null : replacedTx.data.data || '0x'
86
95
  feeAmount = feeOpts.gasPrice.mul(feeOpts.gasLimit)