@exodus/ethereum-api 2.21.6 → 2.22.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": "2.21.6",
3
+ "version": "2.22.1",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -14,14 +14,15 @@
14
14
  "access": "restricted"
15
15
  },
16
16
  "dependencies": {
17
- "@ensdomains/eth-ens-namehash": "^2.0.15",
18
17
  "@exodus/asset-lib": "^3.5.4",
19
18
  "@exodus/crypto": "^1.0.0-rc.0",
20
- "@exodus/ethereum-lib": "^2.19.4",
19
+ "@exodus/ethereum-lib": "^2.20.0",
21
20
  "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
22
21
  "@exodus/simple-retry": "^0.0.6",
23
22
  "@exodus/solidity-contract": "^1.0.1",
24
23
  "fetchival": "0.3.3",
24
+ "idna-uts46-hx": "^2.3.1",
25
+ "js-sha3": "^0.8.0",
25
26
  "make-concurrent": "4.0.0",
26
27
  "minimalistic-assert": "^1.0.1",
27
28
  "ms": "^2.1.1",
@@ -34,5 +35,5 @@
34
35
  "@exodus/assets-base": "^8.0.136",
35
36
  "@exodus/models": "^8.7.2"
36
37
  },
37
- "gitHead": "f5f2bd5dcde6504d06ba68f01385d8215c82d224"
38
+ "gitHead": "6a99fbefed718767bf3f8a81f18881084ffbdb6c"
38
39
  }
package/src/ens/index.js CHANGED
@@ -1,5 +1,6 @@
1
- import { hash } from '@ensdomains/eth-ens-namehash'
2
1
  import SolidityContract from '@exodus/solidity-contract'
2
+ import { toUnicode } from 'idna-uts46-hx'
3
+ import { keccak256 } from 'js-sha3'
3
4
  import { ABI } from '@exodus/ethereum-lib'
4
5
 
5
6
  import ENS_REGISTRY_ADDRESSES from './addresses'
@@ -7,6 +8,35 @@ import ENS_REGISTRY_ADDRESSES from './addresses'
7
8
  const registry = new SolidityContract(ABI.ensRegistry)
8
9
  const resolver = new SolidityContract(ABI.ensResolver)
9
10
 
11
+ function normalize(name) {
12
+ // Implementation based on @ensdomains/eth-ens-namehash package
13
+ return name ? toUnicode(name, { useStd3ASCII: true, transitional: false }) : name
14
+ }
15
+
16
+ function namehash(inputName) {
17
+ // Implementation based on @ensdomains/eth-ens-namehash package
18
+
19
+ // Reject empty names:
20
+ var node = ''
21
+ var i
22
+ for (i = 0; i < 32; i++) {
23
+ node += '00'
24
+ }
25
+
26
+ var name = normalize(inputName)
27
+
28
+ if (name) {
29
+ var labels = name.split('.')
30
+
31
+ for (i = labels.length - 1; i >= 0; i--) {
32
+ var labelSha = keccak256(labels[i])
33
+ node = keccak256(Buffer.from(node + labelSha, 'hex'))
34
+ }
35
+ }
36
+
37
+ return '0x' + node
38
+ }
39
+
10
40
  // ENS only available on mainnet atm
11
41
  const ENS_REGISTRY_ADDRESS = ENS_REGISTRY_ADDRESSES['ethereum']
12
42
 
@@ -14,7 +44,7 @@ const getResolverAddress = async (name: string, server: Object) =>
14
44
  server
15
45
  .ethCall({
16
46
  to: ENS_REGISTRY_ADDRESS,
17
- data: registry.resolver.methodId + hash(name).slice(2),
47
+ data: registry.resolver.methodId + namehash(name).slice(2),
18
48
  })
19
49
  .then((result) => '0x' + result.slice(26))
20
50
 
@@ -22,7 +52,7 @@ const resolveEnsName = async (name: string, server: Object) => {
22
52
  const resolverAddress = await getResolverAddress(name, server)
23
53
  const hex = await server.ethCall({
24
54
  to: resolverAddress,
25
- data: resolver.addr.methodId + hash(name).slice(2),
55
+ data: resolver.addr.methodId + namehash(name).slice(2),
26
56
  })
27
57
  return '0x' + hex.slice(26)
28
58
  }
@@ -34,7 +64,7 @@ const resolveEnsAddress = async (address: string, server: Object) => {
34
64
 
35
65
  const data = await server.ethCall({
36
66
  to: resolverAddress,
37
- data: resolver.name.methodId + hash(name).slice(2),
67
+ data: resolver.name.methodId + namehash(name).slice(2),
38
68
  })
39
69
 
40
70
  return resolver.decodeOutput({ data, method: 'name' })[0]
@@ -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
  }
@@ -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)