@exodus/ethereum-lib 3.3.25 → 3.3.27

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": "3.3.25",
3
+ "version": "3.3.27",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -18,6 +18,7 @@
18
18
  "@exodus/assets": "^8.0.84",
19
19
  "@exodus/aurora-meta": "^1.0.3",
20
20
  "@exodus/avalanchec-meta": "^1.0.4",
21
+ "@exodus/basemainnet-meta": "^1.0.2",
21
22
  "@exodus/basic-utils": "^0.7.0",
22
23
  "@exodus/bip32": "^1.0.0",
23
24
  "@exodus/bsc-meta": "^1.0.14",
@@ -36,12 +37,12 @@
36
37
  "@exodus/matic-meta": "^1.0.9",
37
38
  "@exodus/models": "^8.10.4",
38
39
  "@exodus/optimism-meta": "^1.2.6",
39
- "@exodus/rootstock-meta": "^1.0.4",
40
+ "@exodus/rootstock-meta": "^1.0.5",
40
41
  "@exodus/solidity-contract": "^1.1.3",
41
42
  "base-x": "^3.0.2",
42
43
  "lodash": "^4.17.15",
43
44
  "ms": "^2.1.1",
44
45
  "reselect": "~3.0.1"
45
46
  },
46
- "gitHead": "a56649d200dc1c153e4785416e9b5ead6d17248f"
47
+ "gitHead": "954b8bbebc920fcb88c87a949f7496b59e0379f7"
47
48
  }
@@ -1,12 +1,21 @@
1
1
  import { AccountState } from '@exodus/models'
2
2
 
3
- export default function createEthereumLikeAccountState(asset) {
3
+ import { parseLegacyBalances } from './parse-legacy-balances'
4
+
5
+ // `assets` are only needed for chains that may need legacy parsing support
6
+ export default function createEthereumLikeAccountState(asset, assets = {}) {
4
7
  return class EthereumLikeAccountState extends AccountState {
5
8
  static defaults = {
6
- cursor: '',
9
+ startblock: 0,
7
10
  clarityCursor: '',
8
11
  balance: asset.currency.ZERO,
9
12
  tokenBalances: {},
10
13
  }
14
+
15
+ // legacy -- this should have no effect on Ethereum-like assets that do not have legacy account state
16
+ static _tokens = Object.values(assets)
17
+ static _postParse(data) {
18
+ return { ...data, tokenBalances: parseLegacyBalances(data.tokenBalances, assets) }
19
+ }
11
20
  }
12
21
  }
@@ -0,0 +1,32 @@
1
+ import { isNumberUnit } from '@exodus/currency'
2
+ import { isNumber, isString } from 'lodash'
3
+
4
+ function parseBalance({ asset, balance }) {
5
+ const currency = asset.currency
6
+ if (isNumberUnit(balance)) {
7
+ if (balance.unitType.equals(currency)) {
8
+ return balance
9
+ } else {
10
+ throw new Error(
11
+ `Balance '${balance.toDefaultString()}' is not of currency ${currency.toString()}`
12
+ )
13
+ }
14
+ }
15
+ if (isString(balance)) {
16
+ return currency.parse(balance)
17
+ }
18
+ if (isNumber(balance)) {
19
+ return currency.defaultUnit(balance)
20
+ }
21
+ throw new Error(`Cannot parse balance '${balance}' of currency ${currency}`)
22
+ }
23
+
24
+ export const parseLegacyBalances = (tokenBalances, assets) =>
25
+ Object.fromEntries(
26
+ Object.entries(tokenBalances || {})
27
+ .filter(([assetName]) => assets[assetName])
28
+ .map(([assetName, balance]) => [
29
+ assetName,
30
+ parseBalance({ asset: assets[assetName], balance }),
31
+ ])
32
+ )
@@ -1,9 +1,20 @@
1
1
  import { get } from 'lodash'
2
+ import assets from '@exodus/ethereum-meta'
3
+
4
+ const polygon = assets.find(({ name: tokenName }) => tokenName === 'polygon')
2
5
 
3
6
  export const getPolygonBalances = ({ liquidBalance, accountState }) => {
4
- const delegatedBalance = get(accountState, 'staking.polygon.delegatedBalance')
5
- const unddelegatedBalance = get(accountState, 'staking.polygon.unclaimedUndelegatedBalance')
6
- const totalBalance = liquidBalance.add(delegatedBalance).add(unddelegatedBalance)
7
+ const delegatedBalance = get(
8
+ accountState,
9
+ 'staking.polygon.delegatedBalance',
10
+ polygon.currency.ZERO
11
+ )
12
+ const undelegatedBalance = get(
13
+ accountState,
14
+ 'staking.polygon.unclaimedUndelegatedBalance',
15
+ polygon.currency.ZERO
16
+ )
17
+ const totalBalance = liquidBalance.add(delegatedBalance).add(undelegatedBalance)
7
18
  return {
8
19
  balance: totalBalance,
9
20
  liquidBalance,
@@ -85,8 +85,8 @@ const calculateTxGasPrice = (tx) => tx.feeAmount.div(tx.data.gasLimit)
85
85
 
86
86
  export const calculateBumpedGasPrice = ({ baseAsset, tx, currentGasPrice, eip1559Enabled }) => {
87
87
  const usedGasPrice = calculateTxGasPrice(tx)
88
- let bumpedGasPrice = usedGasPrice.mul(BUMP_RATE)
89
- bumpedGasPrice = currentGasPrice.gt(bumpedGasPrice) ? currentGasPrice : bumpedGasPrice
88
+ const gasPrice = currentGasPrice.gt(usedGasPrice) ? currentGasPrice : usedGasPrice
89
+ const bumpedGasPrice = gasPrice.mul(BUMP_RATE)
90
90
 
91
91
  return eip1559Enabled && tx.data?.tipGasPrice
92
92
  ? {