@exodus/ethereum-api 8.4.2 → 8.6.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/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [8.6.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.5.0...@exodus/ethereum-api@8.6.0) (2024-06-18)
7
+
8
+
9
+ ### Features
10
+
11
+ * add tokenAssetType to base asset ([#2298](https://github.com/ExodusMovement/assets/issues/2298)) ([80c9dc8](https://github.com/ExodusMovement/assets/commit/80c9dc8a4d2a8614f84b66d2c9649cdf19601443))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * add handling 400 error code for eth like ([#2592](https://github.com/ExodusMovement/assets/issues/2592)) ([ac1121d](https://github.com/ExodusMovement/assets/commit/ac1121dab0cc451cfeeb8001915b11fc0bbe00a0))
17
+ * send fromAddress when approving tokens ([#2600](https://github.com/ExodusMovement/assets/issues/2600)) ([25a08ff](https://github.com/ExodusMovement/assets/commit/25a08ff08ca02405fc39d5590c60b025e98e703a))
18
+
19
+
20
+
21
+ ## [8.5.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.4.2...@exodus/ethereum-api@8.5.0) (2024-06-17)
22
+
23
+
24
+ ### Features
25
+
26
+ * balance-utils for getBalances ([#2585](https://github.com/ExodusMovement/assets/issues/2585)) ([ee1aaa6](https://github.com/ExodusMovement/assets/commit/ee1aaa6c669bfdbbc6f3053167b678b98b5ef70d))
27
+
28
+
29
+
6
30
  ## [8.4.2](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.4.1...@exodus/ethereum-api@8.4.2) (2024-06-14)
7
31
 
8
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "8.4.2",
3
+ "version": "8.6.0",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -20,7 +20,7 @@
20
20
  "lint:fix": "yarn lint --fix"
21
21
  },
22
22
  "dependencies": {
23
- "@exodus/asset-lib": "^4.1.0",
23
+ "@exodus/asset-lib": "^4.2.0",
24
24
  "@exodus/assets": "^9.1.1",
25
25
  "@exodus/basic-utils": "^2.1.0",
26
26
  "@exodus/bip44-constants": "^195.0.0",
@@ -66,5 +66,5 @@
66
66
  "type": "git",
67
67
  "url": "git+https://github.com/ExodusMovement/assets.git"
68
68
  },
69
- "gitHead": "af504da8c4e9f5105c30b97b3e08e4e96f1e8fd4"
69
+ "gitHead": "1c873218d5be9cebd41509a7d88c4b003c09d353"
70
70
  }
@@ -33,6 +33,7 @@ export const createApprove =
33
33
  spenderAddress,
34
34
  asset,
35
35
  feeData,
36
+ fromAddress,
36
37
  approveAmount,
37
38
  gasLimit,
38
39
  txInput: preTxInput,
@@ -50,6 +51,7 @@ export const createApprove =
50
51
  txInput,
51
52
  feeData,
52
53
  isContract: true,
54
+ fromAddress,
53
55
  }
54
56
 
55
57
  gasLimit = gasLimit || (await fetchGasLimit(gasLimitOptions))
@@ -64,6 +66,7 @@ export const createApprove =
64
66
  gasPrice: feeData.gasPrice,
65
67
  gasLimit,
66
68
  silent: true,
69
+ fromAddress,
67
70
  ...rest,
68
71
  })
69
72
 
@@ -58,7 +58,6 @@ export const createAssetFactory = ({
58
58
  nfts = false,
59
59
  serverUrl,
60
60
  stakingConfiguration = {},
61
- tokenType,
62
61
  useEip1191ChainIdChecksum = false,
63
62
  }) => {
64
63
  assert(assetsList, 'assetsList is required')
@@ -29,7 +29,7 @@ export function create(defaultURL, ensAssetName) {
29
29
  )
30
30
  } catch (err) {
31
31
  let nerr = err
32
- if (err.response && err.response.status === 500) {
32
+ if (err.response && (err.response.status === 500 || err.response.status === 400)) {
33
33
  try {
34
34
  const data = await err.response.json()
35
35
  const msg = data.error.replace(/^RPC error \(code: -\d+\): /, '')
@@ -1,6 +1,9 @@
1
1
  import {
2
+ // eslint-disable-next-line import/no-deprecated
2
3
  DEFAULT_SERVER_URLS,
4
+ // eslint-disable-next-line import/no-deprecated
3
5
  ETHEREUM_LIKE_ASSETS,
6
+ // eslint-disable-next-line import/no-deprecated
4
7
  ETHEREUM_LIKE_MONITOR_TYPES,
5
8
  } from '@exodus/ethereum-lib'
6
9
 
@@ -27,8 +30,11 @@ export function createEvmServer({ assetName, serverUrl, monitorType }) {
27
30
 
28
31
  // @Deprecated
29
32
  const serverMap = Object.fromEntries(
33
+ // eslint-disable-next-line import/no-deprecated
30
34
  ETHEREUM_LIKE_ASSETS.map((assetName) => {
35
+ // eslint-disable-next-line import/no-deprecated
31
36
  const monitorType = ETHEREUM_LIKE_MONITOR_TYPES[assetName]
37
+ // eslint-disable-next-line import/no-deprecated
32
38
  const serverUrl = DEFAULT_SERVER_URLS[assetName]
33
39
  return [assetName, createEvmServer({ assetName, serverUrl, monitorType })]
34
40
  })
@@ -1,19 +1,12 @@
1
1
  import { isRpcBalanceAsset } from '@exodus/ethereum-lib'
2
2
 
3
3
  import { get } from 'lodash'
4
-
5
- const getBalanceFromAccountState = ({ asset, accountState }) => {
6
- const isBase = asset.name === asset.baseAsset.name
7
- return get(
8
- accountState,
9
- isBase ? ['balance'] : ['tokenBalances', asset.name],
10
- asset.currency.ZERO
11
- )
12
- }
13
-
14
- const getBalanceFromTxLog = ({ txLog, asset }) => {
15
- return txLog.size > 0 ? txLog.getMutations().slice(-1)[0].balance : asset.currency.ZERO
16
- }
4
+ import {
5
+ getBalanceFromAccountState,
6
+ getBalanceFromTxLog,
7
+ getUnconfirmedReceivedBalance,
8
+ getUnconfirmedSentBalance,
9
+ } from '@exodus/asset-lib'
17
10
 
18
11
  const getStaked = ({ accountState, asset }) => {
19
12
  return get(accountState, ['staking', asset.name, 'delegatedBalance']) || asset.currency.ZERO
@@ -29,35 +22,6 @@ const getUnstaked = ({ accountState, asset }) => {
29
22
  )
30
23
  }
31
24
 
32
- const getUnconfirmedSentBalanceFromTxLog = ({ asset, txLog }) => {
33
- let result = asset.currency.ZERO
34
-
35
- for (const tx of txLog) {
36
- const isUnconfirmed = !tx.failed && tx.pending
37
-
38
- if (isUnconfirmed && tx.sent) {
39
- result = result.add(tx.coinAmount.abs())
40
- if (tx.feeAmount && tx.coinAmount.unitType.equals(tx.feeAmount.unitType)) {
41
- result = result.add(tx.feeAmount.abs())
42
- }
43
- }
44
- }
45
-
46
- return result
47
- }
48
-
49
- const getUnconfirmedReceivedBalanceFromTxLog = ({ asset, txLog }) => {
50
- let result = asset.currency.ZERO
51
- for (const tx of txLog) {
52
- const isUnconfirmed = !tx.failed && tx.pending
53
- if (isUnconfirmed && !tx.sent) {
54
- result = result.add(tx.coinAmount.abs())
55
- }
56
- }
57
-
58
- return result
59
- }
60
-
61
25
  /**
62
26
  * Api method to return the balance based on either account state balances or tx history.
63
27
  *
@@ -67,8 +31,8 @@ const getUnconfirmedReceivedBalanceFromTxLog = ({ asset, txLog }) => {
67
31
  * @returns {{balance}|null} an object with the balance or null if the balance is unknown
68
32
  */
69
33
  export const getBalances = ({ asset, txLog, accountState }) => {
70
- const unconfirmedReceived = getUnconfirmedReceivedBalanceFromTxLog({ asset, txLog })
71
- const unconfirmedSent = getUnconfirmedSentBalanceFromTxLog({ asset, txLog })
34
+ const unconfirmedReceived = getUnconfirmedReceivedBalance({ asset, txLog })
35
+ const unconfirmedSent = getUnconfirmedSentBalance({ asset, txLog })
72
36
 
73
37
  // balance from txLog / rpc is considered to be total
74
38
  const balanceWithoutUnconfirmedSent = isRpcBalanceAsset(asset)
@@ -11,10 +11,9 @@ export function createEthereumStakingService({
11
11
  asset,
12
12
  assetClientInterface,
13
13
  createAndBroadcastTX,
14
- getTelemetryId,
15
14
  }) {
16
15
  const staking = new EthereumStaking(asset)
17
- const stakingProvider = stakingProviderClientFactory({ getTelemetryId })
16
+ const stakingProvider = stakingProviderClientFactory()
18
17
 
19
18
  function amountToCurrency({ asset, amount }) {
20
19
  return isNumberUnit(amount) ? amount : asset.currency.parse(amount)
@@ -5,14 +5,10 @@ import { MaticStakingApi } from './api'
5
5
  import { stakingProviderClientFactory } from '../staking-provider-client'
6
6
  import { isNumberUnit } from '@exodus/currency'
7
7
 
8
- export function createPolygonStakingService({
9
- assetClientInterface,
10
- createAndBroadcastTX,
11
- getTelemetryId,
12
- }) {
8
+ export function createPolygonStakingService({ assetClientInterface, createAndBroadcastTX }) {
13
9
  const stakingApi = new MaticStakingApi()
14
10
  const assetName = 'ethereum'
15
- const stakingProvider = stakingProviderClientFactory({ getTelemetryId })
11
+ const stakingProvider = stakingProviderClientFactory()
16
12
 
17
13
  async function getStakeAssets() {
18
14
  const { polygon: asset, ethereum: feeAsset } = await assetClientInterface.getAssetsForNetwork({
@@ -6,7 +6,7 @@ const DEFAULT_STAKING_URL = 'https://staking.a.exodus.io'
6
6
  const HTTP_POST_TIMEOUT = ms('30s')
7
7
 
8
8
  export const stakingProviderClientFactory = (
9
- { defaultStakingUrl = DEFAULT_STAKING_URL, getTelemetryId } = Object.create(null)
9
+ { defaultStakingUrl = DEFAULT_STAKING_URL } = Object.create(null)
10
10
  ) => {
11
11
  assert(defaultStakingUrl, '"defaultStakingUrl" must be provided')
12
12
 
@@ -22,11 +22,8 @@ export const stakingProviderClientFactory = (
22
22
  }
23
23
 
24
24
  const stakingRequest = async ({ asset, data }) => {
25
- const headers = {}
26
- if (typeof getTelemetryId === 'function') headers.telemetryId = await getTelemetryId()
27
25
  return fetchival(stakingUrl, {
28
26
  timeout: HTTP_POST_TIMEOUT,
29
- headers,
30
27
  })(asset)('stake').post(data)
31
28
  }
32
29
 
@@ -1,4 +1,5 @@
1
1
  import { getServer } from '../exodus-eth-server'
2
+ // eslint-disable-next-line import/no-deprecated
2
3
  import { DEFAULT_SERVER_URLS } from '@exodus/ethereum-lib'
3
4
  import { Tx } from '@exodus/models'
4
5
 
@@ -31,6 +32,7 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
31
32
 
32
33
  setServer(config) {
33
34
  if (!config?.server) {
35
+ // eslint-disable-next-line import/no-deprecated
34
36
  this.server.setURI(DEFAULT_SERVER_URLS[this.asset.name])
35
37
  return
36
38
  }