@exodus/ethereum-api 8.20.0 → 8.21.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,29 @@
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.21.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.20.1...@exodus/ethereum-api@8.21.0) (2024-10-28)
7
+
8
+
9
+ ### Features
10
+
11
+ * introduce exodus/ethereumjs ([#4339](https://github.com/ExodusMovement/assets/issues/4339)) ([e81d577](https://github.com/ExodusMovement/assets/commit/e81d5771c4956a22cfcf434a999310bbb5be81a3))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * ETH getBalances with staking info ([#4348](https://github.com/ExodusMovement/assets/issues/4348)) ([19f790c](https://github.com/ExodusMovement/assets/commit/19f790cd6e422307a8c6852d2dd8eca6a16ea95a))
17
+
18
+
19
+
20
+ ## [8.20.1](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.20.0...@exodus/ethereum-api@8.20.1) (2024-10-25)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * remove unconfirmed receive from total balance on evm tokens ([#4338](https://github.com/ExodusMovement/assets/issues/4338)) ([eb5e9af](https://github.com/ExodusMovement/assets/commit/eb5e9afb0cf5b84da6d77d573c77a08a47852b94))
26
+
27
+
28
+
6
29
  ## [8.20.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.19.1...@exodus/ethereum-api@8.20.0) (2024-10-09)
7
30
 
8
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "8.20.0",
3
+ "version": "8.21.0",
4
4
  "description": "Ethereum Api",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -31,7 +31,7 @@
31
31
  "@exodus/ethereum-lib": "^5.4.0",
32
32
  "@exodus/ethereum-meta": "^2.0.0",
33
33
  "@exodus/ethereumholesky-meta": "^2.0.0",
34
- "@exodus/ethereumjs-util": "^7.1.0-exodus.7",
34
+ "@exodus/ethereumjs": "^1.0.0",
35
35
  "@exodus/fetch": "^1.3.0",
36
36
  "@exodus/models": "^12.0.1",
37
37
  "@exodus/simple-retry": "^0.0.6",
@@ -64,5 +64,5 @@
64
64
  "type": "git",
65
65
  "url": "git+https://github.com/ExodusMovement/assets.git"
66
66
  },
67
- "gitHead": "a3826445e762843c0bccc5d9f94ecbb9dfe9648d"
67
+ "gitHead": "348e70ac005cfaf08b3336e86a8cbcd845f5170c"
68
68
  }
@@ -1,4 +1,4 @@
1
- import { bufferToHex } from '@exodus/ethereumjs-util'
1
+ import { bufferToHex } from '@exodus/ethereumjs/util'
2
2
  import SolidityContract from '@exodus/solidity-contract'
3
3
  import EventEmitter from 'events'
4
4
  import lodash from 'lodash'
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from '@exodus/crypto/randomUUID'
2
- import { bufferToHex } from '@exodus/ethereumjs-util'
2
+ import { bufferToHex } from '@exodus/ethereumjs/util'
3
3
  import fetchival from '@exodus/fetch/experimental/fetchival'
4
4
  import { retry } from '@exodus/simple-retry'
5
5
  import SolidityContract from '@exodus/solidity-contract'
@@ -1,4 +1,4 @@
1
- import { bufferToHex } from '@exodus/ethereumjs-util'
1
+ import { bufferToHex } from '@exodus/ethereumjs/util'
2
2
  import SolidityContract from '@exodus/solidity-contract'
3
3
  import EventEmitter from 'events'
4
4
  import io from 'socket.io-client'
@@ -1,5 +1,5 @@
1
1
  import { currency2buffer, isEthereumLikeToken } from '@exodus/ethereum-lib'
2
- import * as ethUtil from '@exodus/ethereumjs-util'
2
+ import { bufferToHex, toBuffer } from '@exodus/ethereumjs/util'
3
3
  import BN from 'bn.js'
4
4
 
5
5
  import { estimateGas, isContractAddressCached } from './eth-like-util.js'
@@ -28,7 +28,7 @@ export async function estimateGasLimit(
28
28
  from: fromAddress,
29
29
  to: toAddress,
30
30
  value: normalizeAmount(amount),
31
- data: Buffer.isBuffer(data) ? ethUtil.bufferToHex(data) : data,
31
+ data: Buffer.isBuffer(data) ? bufferToHex(data) : data,
32
32
  gasPrice: normalizeGasPrice(gasPrice),
33
33
  }
34
34
 
@@ -41,9 +41,7 @@ export async function estimateGasLimit(
41
41
 
42
42
  export function resolveDefaultTxInput({ asset, toAddress, amount }) {
43
43
  return isEthereumLikeToken(asset)
44
- ? ethUtil.bufferToHex(
45
- asset.contract.transfer.build(toAddress.toLowerCase(), amount.toBaseString())
46
- )
44
+ ? bufferToHex(asset.contract.transfer.build(toAddress.toLowerCase(), amount.toBaseString()))
47
45
  : '0x'
48
46
  }
49
47
 
@@ -64,8 +62,7 @@ export async function fetchGasLimit({
64
62
 
65
63
  const txInput = providedTxInput || resolveDefaultTxInput({ asset, toAddress, amount })
66
64
 
67
- const defaultGasLimit = () =>
68
- asset.gasLimit + GAS_PER_NON_ZERO_BYTE * ethUtil.toBuffer(txInput).length
65
+ const defaultGasLimit = () => asset.gasLimit + GAS_PER_NON_ZERO_BYTE * toBuffer(txInput).length
69
66
 
70
67
  const isContract = await isContractAddressCached({ asset, address: toAddress })
71
68
 
@@ -90,7 +87,7 @@ export async function fetchGasLimit({
90
87
  // calling forwarder contracts with a bumped gas limit causes 'Out Of Gas' error on chain
91
88
  // Since geth v1.9.14 estimateGas will throw if user does not have enough ETH.
92
89
  // If gasPrice is set to zero, estimateGas will make the expected estimation.
93
- const gasPrice = ethUtil.bufferToHex(currency2buffer(asset.baseAsset.currency.ZERO))
90
+ const gasPrice = bufferToHex(currency2buffer(asset.baseAsset.currency.ZERO))
94
91
 
95
92
  try {
96
93
  return await estimateGasLimit(
@@ -120,7 +117,7 @@ function normalizeAmount(amount) {
120
117
  amount = currency2buffer(amount)
121
118
  }
122
119
 
123
- amount = ethUtil.bufferToHex(amount)
120
+ amount = bufferToHex(amount)
124
121
  while (amount[2] === '0') amount = '0x' + amount.slice(3)
125
122
  if (amount === '0x') amount = '0x0'
126
123
 
@@ -35,11 +35,20 @@ export const getStakingHistoryBalance = ({ asset, txLog }) => {
35
35
  let stakingHistoryBalance = asset.currency.ZERO
36
36
  for (const tx of txLog) {
37
37
  const successfulTx = tx.confirmations && !tx.failed
38
- if (successfulTx && tx.data?.txAmount) {
38
+ const txData = tx.data
39
+
40
+ // staking tx must has data value
41
+ if (!txData) continue
42
+
43
+ let { txAmount } = txData
44
+ if (successfulTx && (txAmount || txData.delegate)) {
39
45
  // only staking txs have tx.data.txAmount set
40
- // tx.data.txAmount is negative for stake tx type
41
- const txAmount = asset.currency.defaultUnit(tx.data.txAmount)
42
- stakingHistoryBalance = stakingHistoryBalance.add(txAmount)
46
+
47
+ if (txData.delegate && !txAmount) {
48
+ txAmount = txData.delegate // fix missing txAmount in stakeTx
49
+ }
50
+
51
+ stakingHistoryBalance = stakingHistoryBalance.add(asset.currency.defaultUnit(txAmount))
43
52
  }
44
53
  }
45
54
 
@@ -77,7 +86,7 @@ export const getBalancesFactory = ({ monitorType, config = Object.create(null) }
77
86
  // Balance from accountState is considered total b/c is fetched from rpc
78
87
  if (useAccountStateBalanceOnly || isRpcBalanceAsset(asset) || monitorType === 'no-history') {
79
88
  total = getBalanceFromAccountState({ asset, accountState }).sub(unconfirmedSent)
80
- spendable = total.sub(staked).sub(unstaking).sub(unstaked).sub(unconfirmedReceived)
89
+ spendable = total.sub(staked).sub(unstaking).sub(unstaked)
81
90
  } else {
82
91
  // Balance from txLog does not include staking rewards
83
92
  // spendable and total are calculated differently based on staking txs
@@ -87,7 +96,7 @@ export const getBalancesFactory = ({ monitorType, config = Object.create(null) }
87
96
  txLog,
88
97
  unconfirmedReceived,
89
98
  })
90
- total = spendable.add(unconfirmedReceived).add(staked).add(unstaking).add(unstaked)
99
+ total = spendable.add(staked).add(unstaking).add(unstaked)
91
100
  }
92
101
 
93
102
  return {
@@ -1,5 +1,5 @@
1
1
  import { createContract, createEthereumJsTx } from '@exodus/ethereum-lib'
2
- import * as ethUtil from '@exodus/ethereumjs-util'
2
+ import { bufferToHex } from '@exodus/ethereumjs/util'
3
3
  import assert from 'minimalistic-assert'
4
4
 
5
5
  import { fromHexToBigInt } from '../number-utils.js'
@@ -13,7 +13,7 @@ export const estimateL1DataFeeFactory = ({ l1GasOracleAddress, server }) => {
13
13
  const serialized = ethjsTx.serialize()
14
14
  const callData = gasContract.getL1Fee.build(serialized)
15
15
  const buffer = Buffer.from(callData)
16
- const data = ethUtil.bufferToHex(buffer)
16
+ const data = bufferToHex(buffer)
17
17
  const hex = await server.ethCall({ to: l1GasOracleAddress, data }, 'latest')
18
18
  const l1DataFee = fromHexToBigInt(hex)
19
19
  const padFee = l1DataFee / BigInt(4)
@@ -1,5 +1,5 @@
1
1
  import { createContract } from '@exodus/ethereum-lib'
2
- import { bufferToHex } from '@exodus/ethereumjs-util'
2
+ import { bufferToHex } from '@exodus/ethereumjs/util'
3
3
  import { retry } from '@exodus/simple-retry'
4
4
 
5
5
  import { getServerByName } from '../../exodus-eth-server/index.js'
@@ -1,6 +1,6 @@
1
1
  import { createContract } from '@exodus/ethereum-lib'
2
2
  import ethAssets from '@exodus/ethereum-meta'
3
- import { bufferToHex } from '@exodus/ethereumjs-util'
3
+ import { bufferToHex } from '@exodus/ethereumjs/util'
4
4
  import { retry } from '@exodus/simple-retry'
5
5
  import BN from 'bn.js'
6
6
 
@@ -7,8 +7,5 @@ export default function getFeeAmount(asset, serverTx) {
7
7
  // genesis, coinbase, uncles
8
8
  if (!gasPrice) return asset.currency.ZERO
9
9
 
10
- return asset.currency
11
- .baseUnit(gasUsed || gasLimit)
12
- .mul(gasPrice)
13
- .toDefault()
10
+ return asset.currency.baseUnit(gasUsed || gasLimit).mul(gasPrice)
14
11
  }