@exodus/ethereum-api 7.5.1 → 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.1",
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": "220c00b21c6bf4d250aea7a40d37ceebb1716979"
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,8 +172,12 @@ export const createAssetFactory = ({
158
172
  throw new Error(`Monitor type ${monitorType} of evm asset ${asset.name} is unknown`)
159
173
  }
160
174
 
161
- if (supportsStaking) {
162
- const afterTickHook = createEthereumHooks({ assetClientInterface })['after-tick']
175
+ if (stakingAssetNames.length > 0) {
176
+ const afterTickHook = createEthereumHooks({
177
+ assetClientInterface,
178
+ assetName: asset.name,
179
+ stakingAssetNames,
180
+ })['after-tick']
163
181
  monitor.addHook('after-tick', afterTickHook)
164
182
  }
165
183
 
@@ -196,7 +214,11 @@ export const createAssetFactory = ({
196
214
  getDefaultAddressPath: () => defaultAddressPath,
197
215
  getFee,
198
216
  getFeeData: () => feeData,
199
- getKeyIdentifier: createGetKeyIdentifier({ bip44, allowMetaMaskCompat }),
217
+ getKeyIdentifier: createGetKeyIdentifier({
218
+ bip44,
219
+ allowMetaMaskCompat,
220
+ assetName: asset.name,
221
+ }),
200
222
  getSupportedPurposes: () => [44],
201
223
  getTokens,
202
224
  hasFeature: (feature) => !!features[feature], // @deprecated use api.features instead
@@ -70,15 +70,20 @@ export const getBalances = ({ asset, txLog, accountState }) => {
70
70
  const unconfirmedReceived = getUnconfirmedReceivedBalanceFromTxLog({ asset, txLog })
71
71
  const unconfirmedSent = getUnconfirmedSentBalanceFromTxLog({ asset, txLog })
72
72
 
73
+ // balance from txLog / rpc is considered to be total
73
74
  const balanceWithoutUnconfirmedSent = isRpcBalanceAsset(asset)
74
75
  ? getBalanceFromAccountState({ asset, accountState }).sub(unconfirmedSent)
75
76
  : getBalanceFromTxLog({ txLog, asset })
76
77
 
77
- const spendable = balanceWithoutUnconfirmedSent.sub(unconfirmedReceived)
78
78
  const staked = getStaked({ asset, accountState })
79
79
  const unstaking = getUnstaking({ asset, accountState })
80
80
  const unstaked = getUnstaked({ asset, accountState })
81
- const total = balanceWithoutUnconfirmedSent.add(staked).add(unstaking).add(unstaked)
81
+ const total = balanceWithoutUnconfirmedSent
82
+ const spendable = balanceWithoutUnconfirmedSent
83
+ .sub(unconfirmedReceived)
84
+ .sub(staked)
85
+ .sub(unstaking)
86
+ .sub(unstaked)
82
87
 
83
88
  return {
84
89
  // new
@@ -1,83 +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
- const assetName = ethereum.name
14
-
15
11
  const userAddress = await assetClientInterface.getReceiveAddress({
16
12
  assetName,
17
13
  walletAccount,
18
14
  useCache: true,
19
15
  })
20
16
 
21
- const ethereumStakingInfo = await getEthereumStakingInfo({
22
- address: userAddress.toString(),
23
- asset: ethereum,
24
- })
25
-
26
- const polygonStakingInfo = await getPolygonStakingInfo({
27
- address: userAddress.toString(),
28
- asset: polygon,
29
- })
30
-
31
17
  const stakingInfo = {
32
- staking: {
33
- ethereum: ethereumStakingInfo,
34
- polygon: polygonStakingInfo,
35
- },
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
36
29
  }
37
30
 
38
31
  const batch = assetClientInterface.createOperationsBatch()
39
32
  assetClientInterface.updateAccountStateBatch({
40
- assetName: ethereum.name,
33
+ assetName,
41
34
  walletAccount,
42
35
  newData: stakingInfo,
43
36
  batch,
44
37
  })
45
38
 
46
- const processTxLogsPromises = []
47
-
48
- const holeskyAssets = await assetClientInterface.getAssetsForNetwork({
49
- baseAssetName: 'ethereumholesky',
50
- })
51
-
52
- if (!isEmpty(holeskyAssets)) {
53
- const { ethereumholesky } = holeskyAssets
54
- // eslint-disable-next-line no-console
55
- console.log('ethereum-hooks updating holesky state')
56
-
57
- const ethereumHoleskyInfo = await getEthereumStakingInfo({
58
- address: userAddress.toString(),
59
- asset: ethereumholesky,
60
- })
61
-
62
- assetClientInterface.updateAccountStateBatch({
63
- assetName: ethereumholesky.name,
39
+ const processTxLogsPromises = stakingAssetNames.map((stakingAssetName) => {
40
+ return processTxLog({
41
+ asset: assets[stakingAssetName],
42
+ assetClientInterface,
64
43
  walletAccount,
65
- newData: {
66
- staking: {
67
- ethereumholesky: ethereumHoleskyInfo,
68
- },
69
- },
70
44
  batch,
71
45
  })
72
- processTxLogsPromises.push(
73
- processTxLog({ asset: ethereumholesky, assetClientInterface, walletAccount, batch })
74
- )
75
- }
46
+ })
76
47
 
77
- processTxLogsPromises.push(
78
- processTxLog({ asset: polygon, assetClientInterface, walletAccount, batch }),
79
- processTxLog({ asset: ethereum, assetClientInterface, walletAccount, batch })
80
- )
81
48
  await Promise.all(processTxLogsPromises)
82
49
  await assetClientInterface.executeOperationsBatch(batch)
83
50
  }