@exodus/ethereum-lib 0.2.0 → 0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-lib",
3
- "version": "0.2.0",
3
+ "version": "0.2.4",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -19,5 +19,5 @@
19
19
  "devDependencies": {
20
20
  "@exodus/assets": "8.0.x"
21
21
  },
22
- "gitHead": "c04f7f85e7025762fa69cd816adf95c5811455d0"
22
+ "gitHead": "bcaf797f81e5f31a8b15cd2c2efdf6a1ee4c8e65"
23
23
  }
package/src/constants.js CHANGED
@@ -1 +1,3 @@
1
1
  export const CHAIN_IDS = { ethereum: 1, ethereumclassic: 61 }
2
+ export const MIN_GASPRICE = 1e9 // 1 gwei
3
+ export const DEFAULT_FEE_MONITOR_INTERVAL = '1m'
@@ -0,0 +1,32 @@
1
+ import { FeeMonitor } from '@exodus/asset-lib'
2
+ import { DEFAULT_FEE_MONITOR_INTERVAL } from '../constants'
3
+
4
+ export default class EthereumLikeFeeMonitor extends FeeMonitor {
5
+ constructor({
6
+ updateFee,
7
+ interval = DEFAULT_FEE_MONITOR_INTERVAL,
8
+ assetName,
9
+ getGasPrice,
10
+ minGasPrice = 0,
11
+ }) {
12
+ super({ updateFee, interval, assetName })
13
+ this.getGasPrice = getGasPrice
14
+ this.minGasPrice = minGasPrice
15
+ }
16
+
17
+ async fetchFee() {
18
+ let gasPrice = parseInt(await this.getGasPrice(), 16)
19
+
20
+ if (!Number.isFinite(gasPrice)) {
21
+ throw new Error(`Invalid gas price: ${gasPrice}`)
22
+ }
23
+
24
+ if (gasPrice < this.minGasPrice) {
25
+ gasPrice = this.minGasPrice
26
+ }
27
+
28
+ return {
29
+ gasPrice: `${gasPrice} wei`,
30
+ }
31
+ }
32
+ }
@@ -0,0 +1 @@
1
+ export { default as EthereumLikeFeeMonitor } from './ethereum-like'
package/src/index.js CHANGED
@@ -6,3 +6,4 @@ export * from './encode'
6
6
  export * from './unsigned-tx'
7
7
  export * from './utils'
8
8
  export * from './constants'
9
+ export * from './fee-monitor'
package/src/utils.js CHANGED
@@ -26,3 +26,8 @@ export function currency2buffer(value) {
26
26
 
27
27
  return Buffer.from(ethUtil.padToEven(hexValue), 'hex')
28
28
  }
29
+
30
+ export function normalizeTxId(txId: string): string {
31
+ if (txId.startsWith('0x')) return txId
32
+ else return '0x' + txId
33
+ }