@exodus/ethereum-api 2.21.5 → 2.22.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/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "2.21.5",
3
+ "version": "2.22.0",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
+ "files": [
7
+ "src",
8
+ "!src/**/__tests__"
9
+ ],
6
10
  "author": "Exodus Movement, Inc.",
7
11
  "license": "UNLICENSED",
8
12
  "homepage": "https://github.com/ExodusMovement/ethereum#readme",
@@ -13,7 +17,7 @@
13
17
  "@ensdomains/eth-ens-namehash": "^2.0.15",
14
18
  "@exodus/asset-lib": "^3.5.4",
15
19
  "@exodus/crypto": "^1.0.0-rc.0",
16
- "@exodus/ethereum-lib": "^2.19.3",
20
+ "@exodus/ethereum-lib": "^2.20.0",
17
21
  "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
18
22
  "@exodus/simple-retry": "^0.0.6",
19
23
  "@exodus/solidity-contract": "^1.0.1",
@@ -30,5 +34,5 @@
30
34
  "@exodus/assets-base": "^8.0.136",
31
35
  "@exodus/models": "^8.7.2"
32
36
  },
33
- "gitHead": "17da5c475386e928e677702982b5e757c0f3870b"
37
+ "gitHead": "57fae619663ea5193c733bd089c9031447f0d025"
34
38
  }
package/src/ens/index.js CHANGED
@@ -2,7 +2,6 @@ import { hash } from '@ensdomains/eth-ens-namehash'
2
2
  import SolidityContract from '@exodus/solidity-contract'
3
3
  import { ABI } from '@exodus/ethereum-lib'
4
4
 
5
- import { eth as server } from '../exodus-eth-server'
6
5
  import ENS_REGISTRY_ADDRESSES from './addresses'
7
6
 
8
7
  const registry = new SolidityContract(ABI.ensRegistry)
@@ -11,7 +10,7 @@ const resolver = new SolidityContract(ABI.ensResolver)
11
10
  // ENS only available on mainnet atm
12
11
  const ENS_REGISTRY_ADDRESS = ENS_REGISTRY_ADDRESSES['ethereum']
13
12
 
14
- const getResolverAddress = async (name: string) =>
13
+ const getResolverAddress = async (name: string, server: Object) =>
15
14
  server
16
15
  .ethCall({
17
16
  to: ENS_REGISTRY_ADDRESS,
@@ -19,8 +18,8 @@ const getResolverAddress = async (name: string) =>
19
18
  })
20
19
  .then((result) => '0x' + result.slice(26))
21
20
 
22
- const resolveEnsName = async (name: string) => {
23
- const resolverAddress = await getResolverAddress(name)
21
+ const resolveEnsName = async (name: string, server: Object) => {
22
+ const resolverAddress = await getResolverAddress(name, server)
24
23
  const hex = await server.ethCall({
25
24
  to: resolverAddress,
26
25
  data: resolver.addr.methodId + hash(name).slice(2),
@@ -28,10 +27,10 @@ const resolveEnsName = async (name: string) => {
28
27
  return '0x' + hex.slice(26)
29
28
  }
30
29
 
31
- const resolveEnsAddress = async (address: string) => {
30
+ const resolveEnsAddress = async (address: string, server: Object) => {
32
31
  const name = `${address.slice(2)}.addr.reverse`
33
32
 
34
- const resolverAddress = await getResolverAddress(name)
33
+ const resolverAddress = await getResolverAddress(name, server)
35
34
 
36
35
  const data = await server.ethCall({
37
36
  to: resolverAddress,
@@ -1,15 +1,13 @@
1
1
  import { normalizeTxId, isEthereumLikeAsset, isEthereumLikeToken, ABI } from '@exodus/ethereum-lib'
2
- import { eth, serverMap, getServer } from './exodus-eth-server'
2
+ import { getServerByName, getServer } from './exodus-eth-server'
3
3
  import { memoizeLruCache } from '@exodus/asset-lib'
4
4
  import assets from '@exodus/assets'
5
5
  import SolidityContract from '@exodus/solidity-contract'
6
6
 
7
7
  // Mobile only.
8
- // Behavior is buggy, because the default server used is ethereum.
9
8
  // We should refactor mobile to pass 'asset' instead of 'assetName' so that we can use 'isContractAddress'. But that would touch many assets.
10
9
  export async function isContract(baseAssetName, address) {
11
- const server = serverMap[baseAssetName] || eth
12
- return server.isContract(address)
10
+ return getServerByName(baseAssetName).isContract(address)
13
11
  }
14
12
 
15
13
  export async function isContractAddress({ asset, address }) {
@@ -245,8 +245,8 @@ export function create(defaultURL, ensAssetName) {
245
245
  return ensAssetName === 'ethereum'
246
246
  ? {
247
247
  ...api,
248
- resolveEnsName,
249
- resolveEnsAddress,
248
+ resolveEnsName: (name) => resolveEnsName(name, api),
249
+ resolveEnsAddress: (address) => resolveEnsAddress(address, api),
250
250
  }
251
251
  : api
252
252
  }
@@ -2,8 +2,7 @@ import { DEFAULT_SERVER_URLS, ETHEREUM_LIKE_ASSETS } from '@exodus/ethereum-lib'
2
2
 
3
3
  import { create } from './api'
4
4
 
5
- // exported for in-library use only.
6
- export const serverMap = Object.fromEntries(
5
+ const serverMap = Object.fromEntries(
7
6
  ETHEREUM_LIKE_ASSETS.map((assetName) => [
8
7
  assetName,
9
8
  create(DEFAULT_SERVER_URLS[assetName], assetName),
@@ -12,16 +11,26 @@ export const serverMap = Object.fromEntries(
12
11
 
13
12
  // allow self-signed certs
14
13
  // process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
14
+ // @deprecated Use getServer or getServerbyName instead
15
15
  export const eth = serverMap['ethereum']
16
+ // @deprecated Use getServer or getServerbyName instead
16
17
  export const etc = serverMap['ethereumclassic']
18
+ // @deprecated Use getServer or getServerbyName instead
17
19
  export const bsc = serverMap['bsc']
20
+ // @deprecated Use getServer or getServerbyName instead
18
21
  export const polygon = serverMap['matic']
22
+ // @deprecated Use getServer or getServerbyName instead
19
23
  export const avaxc = serverMap['avalanchec']
24
+ // @deprecated Use getServer or getServerbyName instead
20
25
  export const ftm = serverMap['fantommainnet']
26
+ // @deprecated Use getServer or getServerbyName instead
21
27
  export const harmony = serverMap['harmonymainnet']
22
28
 
23
29
  export function getServer(asset) {
24
- const baseAssetName = asset.baseAsset.name
30
+ return getServerByName(asset.baseAsset.name)
31
+ }
32
+
33
+ export function getServerByName(baseAssetName) {
25
34
  const server = serverMap[baseAssetName]
26
35
  if (!server) throw new Error(`unsupported base asset ${baseAssetName}`)
27
36
  return server
@@ -37,7 +37,7 @@ export default function createWebSocket(getURL) {
37
37
  events.emit(`address-${data.address}`)
38
38
  break
39
39
  case 'gasprice':
40
- events.emit('gasprice', data.gasprice)
40
+ events.emit('gasprice', { gasPrice: data.gasprice, baseFeePerGas: data.baseGasPrice })
41
41
  break
42
42
  }
43
43
  }
@@ -1,12 +1,14 @@
1
1
  import { EthereumLikeFeeMonitor } from '@exodus/ethereum-lib'
2
- import { avaxc as avalancheServer } from '../exodus-eth-server'
2
+ import { getServerByName } from '../exodus-eth-server'
3
+
4
+ const assetName = 'avalanchec'
3
5
 
4
6
  export class AvalancheFeeMonitor extends EthereumLikeFeeMonitor {
5
7
  constructor({ updateFee }) {
6
8
  super({
7
9
  updateFee,
8
- assetName: 'avalanchec',
9
- getGasPrice: avalancheServer.gasPrice,
10
+ assetName,
11
+ getGasPrice: getServerByName(assetName).gasPrice,
10
12
  })
11
13
  }
12
14
  }
@@ -1,12 +1,14 @@
1
1
  import { EthereumLikeFeeMonitor } from '@exodus/ethereum-lib'
2
- import { bsc } from '../exodus-eth-server'
2
+ import { getServerByName } from '../exodus-eth-server'
3
+
4
+ const assetName = 'bsc'
3
5
 
4
6
  export class BscFeeMonitor extends EthereumLikeFeeMonitor {
5
7
  constructor({ updateFee }) {
6
8
  super({
7
9
  updateFee,
8
- assetName: 'bsc',
9
- getGasPrice: bsc.gasPrice,
10
+ assetName,
11
+ getGasPrice: getServerByName(assetName).gasPrice,
10
12
  })
11
13
  }
12
14
  }
@@ -1,12 +1,14 @@
1
1
  import { EthereumLikeFeeMonitor } from '@exodus/ethereum-lib'
2
- import { eth as ethServer } from '../exodus-eth-server'
2
+ import { getServerByName } from '../exodus-eth-server'
3
+
4
+ const assetName = 'ethereum'
3
5
 
4
6
  export class EthereumFeeMonitor extends EthereumLikeFeeMonitor {
5
7
  constructor({ updateFee, interval }) {
6
8
  super({
7
9
  updateFee,
8
- assetName: 'ethereum',
9
- getGasPrice: ethServer.gasPrice,
10
+ assetName,
11
+ getGasPrice: getServerByName(assetName).gasPrice,
10
12
  interval,
11
13
  })
12
14
  }
@@ -1,12 +1,14 @@
1
1
  import { EthereumLikeFeeMonitor } from '@exodus/ethereum-lib'
2
- import { etc as etcServer } from '../exodus-eth-server'
2
+ import { getServerByName } from '../exodus-eth-server'
3
+
4
+ const assetName = 'ethereumclassic'
3
5
 
4
6
  export class EthereumClassicFeeMonitor extends EthereumLikeFeeMonitor {
5
7
  constructor({ updateFee }) {
6
8
  super({
7
9
  updateFee,
8
- assetName: 'ethereumclassic',
9
- getGasPrice: etcServer.gasPrice,
10
+ assetName,
11
+ getGasPrice: getServerByName(assetName).gasPrice,
10
12
  })
11
13
  }
12
14
  }
@@ -1,12 +1,14 @@
1
1
  import { EthereumLikeFeeMonitor } from '@exodus/ethereum-lib'
2
- import { ftm as fantomServer } from '../exodus-eth-server'
2
+ import { getServerByName } from '../exodus-eth-server'
3
+
4
+ const assetName = 'fantommainnet'
3
5
 
4
6
  export class FantomFeeMonitor extends EthereumLikeFeeMonitor {
5
7
  constructor({ updateFee }) {
6
8
  super({
7
9
  updateFee,
8
- assetName: 'fantommainnet',
9
- getGasPrice: fantomServer.gasPrice,
10
+ assetName,
11
+ getGasPrice: getServerByName(assetName).gasPrice,
10
12
  })
11
13
  }
12
14
  }
@@ -1,12 +1,14 @@
1
1
  import { EthereumLikeFeeMonitor } from '@exodus/ethereum-lib'
2
- import { harmony as harmonyServer } from '../exodus-eth-server'
2
+ import { getServerByName } from '../exodus-eth-server'
3
+
4
+ const assetName = 'harmonymainnet'
3
5
 
4
6
  export class HarmonyFeeMonitor extends EthereumLikeFeeMonitor {
5
7
  constructor({ updateFee }) {
6
8
  super({
7
9
  updateFee,
8
- assetName: 'harmonymainnet',
9
- getGasPrice: harmonyServer.gasPrice,
10
+ assetName,
11
+ getGasPrice: getServerByName(assetName).gasPrice,
10
12
  })
11
13
  }
12
14
  }
@@ -1,12 +1,14 @@
1
1
  import { EthereumLikeFeeMonitor } from '@exodus/ethereum-lib'
2
- import { polygon as polygonServer } from '../exodus-eth-server'
2
+ import { getServerByName } from '../exodus-eth-server'
3
+
4
+ const assetName = 'matic'
3
5
 
4
6
  export class PolygonFeeMonitor extends EthereumLikeFeeMonitor {
5
7
  constructor({ updateFee }) {
6
8
  super({
7
9
  updateFee,
8
- assetName: 'matic',
9
- getGasPrice: polygonServer.gasPrice,
10
+ assetName,
11
+ getGasPrice: getServerByName(assetName).gasPrice,
10
12
  })
11
13
  }
12
14
  }
@@ -1,5 +1,5 @@
1
1
  import { createContract } from '@exodus/ethereum-lib'
2
- import { eth } from '../exodus-eth-server'
2
+ import { getServerByName } from '../exodus-eth-server'
3
3
  import { retry } from '@exodus/simple-retry'
4
4
  import { bufferToHex } from '@exodus/ethereumjs-util'
5
5
 
@@ -27,6 +27,8 @@ export class MaticStaking {
27
27
  tag: 'latest',
28
28
  }
29
29
 
30
+ // TODO: why 'ethereum' if this is matic staking?
31
+ const eth = getServerByName('ethereum')
30
32
  return retry(eth.ethCall, { delayTimesMs: RETRY_DELAYS })(data)
31
33
  }
32
34
 
@@ -199,10 +199,18 @@ export class EthereumMonitor extends BaseMonitor {
199
199
  }
200
200
  }
201
201
 
202
- async updateGasPrice(newGasPrice) {
202
+ async updateGasPrice({ gasPrice, baseFeePerGas }) {
203
203
  try {
204
- const feeConfig = { gasPrice: `${parseInt(newGasPrice, 16)} wei` }
205
- this.logger.debug(`Update ${this.asset.name} gas price: ${feeConfig.gasPrice}`)
204
+ const feeConfig = {
205
+ gasPrice: `${parseInt(gasPrice, 16)} wei`,
206
+ }
207
+ if (baseFeePerGas) {
208
+ feeConfig.baseFeePerGas = `${parseInt(baseFeePerGas, 16)} wei`
209
+ }
210
+
211
+ this.logger.debug(
212
+ `Update ${this.asset.name} gas price: ${feeConfig.gasPrice}, baseFeePerGas: ${feeConfig.baseFeePerGas}`
213
+ )
206
214
  await this.aci.updateFeeConfig({ assetName: this.asset.name, feeConfig })
207
215
  } catch (e) {
208
216
  this.logger.warn('error updating gasPrice', e)