@exodus/ethereum-api 7.5.2 → 7.5.3

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.5.2",
3
+ "version": "7.5.3",
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.8.1",
28
+ "@exodus/ethereum-lib": "^4.9.0",
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": "8f0211c5cbdc7117872f2f910c9b31d7e4e106f0"
60
+ "gitHead": "9322a03c6b00b6dc765356309b3e8f1e1f27df41"
61
61
  }
@@ -38,6 +38,7 @@ import { txSendFactory } from './tx-send'
38
38
  import { serverBasedFeeMonitorFactoryFactory } from './fee-monitor'
39
39
  import { createGetBalanceForAddress } from './get-balance-for-address'
40
40
  import { estimateL1DataFeeFactory, getL1GetFeeFactory } from './optimism-gas'
41
+ import { mapValues } from 'lodash'
41
42
 
42
43
  export const createAssetFactory = ({
43
44
  assetsList,
@@ -55,6 +56,7 @@ export const createAssetFactory = ({
55
56
  customCreateGetKeyIdentifier,
56
57
  feeMonitorInterval,
57
58
  l1GasOracleAddress, // l1 extra fee for base and opto
59
+ stakingConfiguration = {},
58
60
  }) => {
59
61
  assert(assetsList, 'assetsList is required')
60
62
  assert(feeData, 'feeData is required')
@@ -135,8 +137,20 @@ export const createAssetFactory = ({
135
137
 
136
138
  const confirmationNumber = CONFIRMATIONS_NUMBER[asset.name] || 1
137
139
 
140
+ const stakingAssetNames = Object.keys(stakingConfiguration)
141
+
142
+ const extraData =
143
+ stakingAssetNames.length > 0
144
+ ? {
145
+ staking: mapValues(
146
+ stakingConfiguration,
147
+ (assetStakinConfiguration) => assetStakinConfiguration.accountStateExtraData
148
+ ),
149
+ }
150
+ : undefined
151
+
138
152
  const accountStateClass =
139
- CustomAccountState || createEthereumLikeAccountState({ asset: base, assets })
153
+ CustomAccountState || createEthereumLikeAccountState({ asset: base, assets, extraData })
140
154
 
141
155
  const createHistoryMonitor = (args) => {
142
156
  let monitor
@@ -158,10 +172,14 @@ export const createAssetFactory = ({
158
172
  throw new Error(`Monitor type ${monitorType} of evm asset ${asset.name} is unknown`)
159
173
  }
160
174
 
161
- // always run hooks that modify staking txs to have consistent balances
162
- // revisit later to only run this hook ONLY if supportsStaking = true
163
- const afterTickHook = createEthereumHooks({ assetClientInterface })['after-tick']
164
- monitor.addHook('after-tick', afterTickHook)
175
+ if (stakingAssetNames.length > 0) {
176
+ const afterTickHook = createEthereumHooks({
177
+ assetClientInterface,
178
+ assetName: asset.name,
179
+ stakingAssetNames,
180
+ })['after-tick']
181
+ monitor.addHook('after-tick', afterTickHook)
182
+ }
165
183
 
166
184
  return monitor
167
185
  }
@@ -1,91 +1,50 @@
1
1
  import { getEthereumStakingInfo, getPolygonStakingInfo } from '../staking'
2
- import { isEmpty } from 'lodash'
3
-
4
2
  import processTxLog from '../tx-log-staking-processor'
5
3
 
6
- export const createEthereumHooks = ({ assetClientInterface }) => {
4
+ export const createEthereumHooks = ({ assetClientInterface, assetName, stakingAssetNames }) => {
7
5
  const afterTickHook = async ({ walletAccount }) => {
8
6
  // args passed from monitor tick method ({ monitor, error })
9
- const { ethereum, polygon } = await assetClientInterface.getAssetsForNetwork({
10
- baseAssetName: 'ethereum',
7
+ const assets = await assetClientInterface.getAssetsForNetwork({
8
+ baseAssetName: assetName,
11
9
  })
12
10
 
13
- // polygon on ETH is not supported in ME
14
- // TODO: remove this once this hook only runs for wallets that support staking
15
- const isPolygonSupported = !!polygon
16
-
17
- const assetName = ethereum.name
18
-
19
11
  const userAddress = await assetClientInterface.getReceiveAddress({
20
12
  assetName,
21
13
  walletAccount,
22
14
  useCache: true,
23
15
  })
24
16
 
25
- const ethereumStakingInfo = await getEthereumStakingInfo({
26
- address: userAddress.toString(),
27
- asset: ethereum,
28
- })
29
-
30
- const polygonStakingInfo = isPolygonSupported
31
- ? await getPolygonStakingInfo({
32
- address: userAddress.toString(),
33
- asset: polygon,
34
- })
35
- : {}
36
-
37
17
  const stakingInfo = {
38
- staking: {
39
- ethereum: ethereumStakingInfo,
40
- polygon: polygonStakingInfo,
41
- },
18
+ staking: Object.create(null),
19
+ }
20
+
21
+ for (const stakingAssetName of stakingAssetNames) {
22
+ const getStakingInfo =
23
+ stakingAssetName === 'polygon' ? getPolygonStakingInfo : getEthereumStakingInfo
24
+ const assetStakingInfo = await getStakingInfo({
25
+ address: userAddress.toString(),
26
+ asset: assets[stakingAssetName],
27
+ })
28
+ stakingInfo.staking[stakingAssetName] = assetStakingInfo
42
29
  }
43
30
 
44
31
  const batch = assetClientInterface.createOperationsBatch()
45
32
  assetClientInterface.updateAccountStateBatch({
46
- assetName: ethereum.name,
33
+ assetName,
47
34
  walletAccount,
48
35
  newData: stakingInfo,
49
36
  batch,
50
37
  })
51
38
 
52
- const processTxLogsPromises = []
53
-
54
- const holeskyAssets = await assetClientInterface.getAssetsForNetwork({
55
- baseAssetName: 'ethereumholesky',
56
- })
57
-
58
- if (!isEmpty(holeskyAssets)) {
59
- const { ethereumholesky } = holeskyAssets
60
- // eslint-disable-next-line no-console
61
- console.log('ethereum-hooks updating holesky state')
62
-
63
- const ethereumHoleskyInfo = await getEthereumStakingInfo({
64
- address: userAddress.toString(),
65
- asset: ethereumholesky,
66
- })
67
-
68
- assetClientInterface.updateAccountStateBatch({
69
- assetName: ethereumholesky.name,
39
+ const processTxLogsPromises = stakingAssetNames.map((stakingAssetName) => {
40
+ return processTxLog({
41
+ asset: assets[stakingAssetName],
42
+ assetClientInterface,
70
43
  walletAccount,
71
- newData: {
72
- staking: {
73
- ethereumholesky: ethereumHoleskyInfo,
74
- },
75
- },
76
44
  batch,
77
45
  })
78
- processTxLogsPromises.push(
79
- processTxLog({ asset: ethereumholesky, assetClientInterface, walletAccount, batch })
80
- )
81
- }
46
+ })
82
47
 
83
- processTxLogsPromises.push(
84
- ...(isPolygonSupported
85
- ? [processTxLog({ asset: polygon, assetClientInterface, walletAccount, batch })]
86
- : []),
87
- processTxLog({ asset: ethereum, assetClientInterface, walletAccount, batch })
88
- )
89
48
  await Promise.all(processTxLogsPromises)
90
49
  await assetClientInterface.executeOperationsBatch(batch)
91
50
  }