@exodus/ethereum-api 8.21.3 → 8.22.1

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,26 @@
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.22.1](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.22.0...@exodus/ethereum-api@8.22.1) (2024-12-03)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+
12
+ * fix: increase gasLimit estimation when from or to address are unknown (#4594)
13
+
14
+
15
+
16
+ ## [8.22.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.21.3...@exodus/ethereum-api@8.22.0) (2024-12-02)
17
+
18
+
19
+ ### Features
20
+
21
+
22
+ * feat: gasPriceMaximumRate in evm fee data (#4578)
23
+
24
+
25
+
6
26
  ## [8.21.3](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.21.2...@exodus/ethereum-api@8.21.3) (2024-11-27)
7
27
 
8
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "8.21.3",
3
+ "version": "8.22.1",
4
4
  "description": "Transaction monitors, fee monitors, RPC with the blockchain node, and other networking code for Ethereum and EVM-based blockchains",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -64,5 +64,5 @@
64
64
  "type": "git",
65
65
  "url": "git+https://github.com/ExodusMovement/assets.git"
66
66
  },
67
- "gitHead": "391020017026fc2d06ff3d7f164a5c91a6922c3f"
67
+ "gitHead": "3388dd56aaa85965b27bc8a13e92f098a43cba58"
68
68
  }
@@ -1,6 +1,4 @@
1
1
  import { createMetaDef } from '@exodus/asset'
2
- import { FeeData } from '@exodus/asset-lib'
3
- import { UnitType } from '@exodus/currency'
4
2
  import assert from 'minimalistic-assert'
5
3
 
6
4
  import { createAssetFactory } from './create-asset.js'
@@ -27,8 +25,6 @@ export const createAssetPluginFactory = (config) => {
27
25
  [ticker]: decimals || 18,
28
26
  }
29
27
 
30
- const currency = UnitType.create(units)
31
-
32
28
  // adds lots of validation in config
33
29
  const tokenOverrides = (token) => ({
34
30
  ...token,
@@ -43,7 +39,7 @@ export const createAssetPluginFactory = (config) => {
43
39
  }
44
40
 
45
41
  const assetType = 'ETHEREUM_LIKE'
46
- const { asset, assetsList } = createMetaDef({
42
+ const { assetsList } = createMetaDef({
47
43
  assetParams: {
48
44
  ...meta,
49
45
  name,
@@ -56,61 +52,17 @@ export const createAssetPluginFactory = (config) => {
56
52
  tokensParams: meta.tokens || [],
57
53
  tokenOverrides,
58
54
  })
59
-
60
- const resolveFeeDataConfigDefaults = () => {
61
- const shared = {
62
- tipGasPrice: '0 Gwei',
63
- fuelThreshold: '0 Gwei',
64
- gasPriceEconomicalRate: 0.8,
65
- gasPriceMinimumRate: 0.6,
66
- }
67
-
68
- if (config.eip1559Enabled === true) {
69
- assert(config.baseFeePerGas, 'baseFeePerGas is required')
70
- const baseFeePerGas = currency.parse(config.baseFeePerGas)
71
- const gasPrice = config.gasPrice ? currency.parse(config.gasPrice) : baseFeePerGas.mul(1.5)
72
- return {
73
- gasPrice: gasPrice.toBaseString({ unit: true }),
74
- baseFeePerGas: baseFeePerGas.toBaseString({ unit: true }),
75
- max: gasPrice.mul(5).toBaseString({ unit: true }),
76
- min: gasPrice.div(5).toBaseString({ unit: true }),
77
- eip1559Enabled: config.eip1559Enabled,
78
- ...shared,
79
- ...config.feeData,
80
- }
81
- }
82
-
83
- if (config.eip1559Enabled === false) {
84
- assert(config.gasPrice, 'gasPrice is required')
85
- const gasPrice = currency.parse(config.gasPrice)
86
- return {
87
- gasPrice: gasPrice.toBaseString({ unit: true }),
88
- max: gasPrice.mul(5).toBaseString({ unit: true }),
89
- min: gasPrice.div(5).toBaseString({ unit: true }),
90
- eip1559Enabled: config.eip1559Enabled,
91
- ...shared,
92
- ...config.feeData,
93
- }
94
- }
95
-
96
- return {
97
- gasPrice: '0.02 Gwei',
98
- baseFeePerGas: '0.02 Gwei',
99
- eip1559Enabled: true,
100
- ...shared,
55
+ const feeDataConfig = Object.fromEntries(
56
+ Object.entries({
57
+ gasPrice: config.gasPrice,
58
+ baseFeePerGas: config.baseFeePerGas,
59
+ eip1559Enabled: config.eip1559Enabled,
101
60
  ...config.feeData,
102
- }
103
- }
104
-
105
- const feeData = new FeeData({
106
- config: resolveFeeDataConfigDefaults(),
107
- mainKey: 'gasPrice',
108
- currency: asset.currency,
109
- })
110
-
61
+ }).filter(([_, value]) => value !== undefined)
62
+ )
111
63
  const createAsset = createAssetFactory({
112
64
  assetsList,
113
- feeData,
65
+ feeDataConfig,
114
66
  ...config.plugin,
115
67
  })
116
68
 
@@ -23,6 +23,7 @@ import ms from 'ms'
23
23
  import { addressHasHistoryFactory } from './address-has-history.js'
24
24
  import { createTokenFactory } from './create-token-factory.js'
25
25
  import { createEvmServer } from './exodus-eth-server/index.js'
26
+ import { createFeeData } from './fee-data-factory.js'
26
27
  import { createGetBalanceForAddress } from './get-balance-for-address.js'
27
28
  import { getBalancesFactory } from './get-balances.js'
28
29
  import { getEffectiveGasPrice, getFeeFactory } from './get-fee.js'
@@ -47,7 +48,8 @@ export const createAssetFactory = ({
47
48
  customCreateGetKeyIdentifier,
48
49
  customTokens: defaultCustomTokens = true,
49
50
  erc20FuelBuffer,
50
- feeData,
51
+ feeData: providedFeeData,
52
+ feeDataConfig,
51
53
  feeMonitorInterval,
52
54
  fuelThreshold,
53
55
  isMaxFeeAsset = false,
@@ -62,11 +64,13 @@ export const createAssetFactory = ({
62
64
  forceGasLimitEstimation = false,
63
65
  }) => {
64
66
  assert(assetsList, 'assetsList is required')
65
- assert(feeData, 'feeData is required')
67
+ assert(providedFeeData || feeDataConfig, 'feeData or feeDataConfig is required')
66
68
  assert(serverUrl, 'serverUrl is required')
67
69
  assert(confirmationsNumber, 'confirmationsNumber is required')
68
70
 
69
71
  const base = assetsList.find((asset) => asset.name === asset.baseAssetName)
72
+
73
+ const feeData = providedFeeData || createFeeData({ currency: base.currency, feeDataConfig })
70
74
  assert(base, 'base is required')
71
75
 
72
76
  const chainId = base.chainId
@@ -7,6 +7,9 @@ import * as ErrorWrapper from './error-wrapper.js'
7
7
  import { getServer, getServerByName } from './exodus-eth-server/index.js'
8
8
  import { fromHexToString } from './number-utils.js'
9
9
 
10
+ export const FORWARDER_CONTRACT_CODE =
11
+ '0x5836818037808036817364b29dc43e817817cf77468c8dda63d98ce08fb25af43d91908282803e602b57fd5bf3'
12
+
10
13
  export async function isContract(baseAssetName, address) {
11
14
  return getServerByName(baseAssetName).isContract(address)
12
15
  }
@@ -22,11 +25,9 @@ export const isContractAddressCached = memoizeLruCache(
22
25
  )
23
26
 
24
27
  export async function isForwarderContract({ asset, address }) {
25
- const contractCode = await getServer(asset).getCode(address)
26
- return (
27
- contractCode ===
28
- '0x5836818037808036817364b29dc43e817817cf77468c8dda63d98ce08fb25af43d91908282803e602b57fd5bf3'
29
- )
28
+ const server = getServer(asset)
29
+ const contractCode = await server.getCode(address)
30
+ return contractCode === FORWARDER_CONTRACT_CODE
30
31
  }
31
32
 
32
33
  export const isForwarderContractCached = memoizeLruCache(
@@ -0,0 +1,56 @@
1
+ import { FeeData } from '@exodus/asset-lib'
2
+ import assert from 'minimalistic-assert'
3
+
4
+ const createFeeDataConfigDefaults = ({ currency, feeDataConfig }) => {
5
+ const shared = {
6
+ tipGasPrice: '0 Gwei',
7
+ fuelThreshold: '0 Gwei',
8
+ gasPriceEconomicalRate: 0.8,
9
+ gasPriceMinimumRate: 0.6,
10
+ gasPriceMaximumRate: 1.3,
11
+ }
12
+
13
+ if (feeDataConfig.eip1559Enabled === true) {
14
+ assert(feeDataConfig.baseFeePerGas, 'baseFeePerGas is required')
15
+ const baseFeePerGas = currency.parse(feeDataConfig.baseFeePerGas)
16
+ const gasPrice = feeDataConfig.gasPrice
17
+ ? currency.parse(feeDataConfig.gasPrice)
18
+ : baseFeePerGas.mul(1.5)
19
+ return {
20
+ gasPrice: gasPrice.toBaseString({ unit: true }),
21
+ baseFeePerGas: baseFeePerGas.toBaseString({ unit: true }),
22
+ eip1559Enabled: feeDataConfig.eip1559Enabled,
23
+ ...shared,
24
+ ...feeDataConfig,
25
+ }
26
+ }
27
+
28
+ if (feeDataConfig.eip1559Enabled === false) {
29
+ assert(feeDataConfig.gasPrice, 'gasPrice is required')
30
+ const gasPrice = currency.parse(feeDataConfig.gasPrice)
31
+ return {
32
+ gasPrice: gasPrice.toBaseString({ unit: true }),
33
+ max: gasPrice.mul(5).toBaseString({ unit: true }),
34
+ min: gasPrice.div(5).toBaseString({ unit: true }),
35
+ eip1559Enabled: feeDataConfig.eip1559Enabled,
36
+ ...shared,
37
+ ...feeDataConfig,
38
+ }
39
+ }
40
+
41
+ return {
42
+ gasPrice: '0.02 Gwei',
43
+ baseFeePerGas: '0.02 Gwei',
44
+ eip1559Enabled: true,
45
+ ...shared,
46
+ ...feeDataConfig,
47
+ }
48
+ }
49
+
50
+ export const createFeeData = ({ currency, feeDataConfig }) => {
51
+ return new FeeData({
52
+ config: createFeeDataConfigDefaults({ currency, feeDataConfig }),
53
+ mainKey: 'gasPrice',
54
+ currency,
55
+ })
56
+ }
@@ -4,7 +4,7 @@ import BN from 'bn.js'
4
4
 
5
5
  import { estimateGas, isContractAddressCached } from './eth-like-util.js'
6
6
 
7
- const EXTRA_PERCENTAGE = 20
7
+ export const EXTRA_PERCENTAGE = 20
8
8
 
9
9
  // 16 gas per non-zero byte (4 gas per zero byte) of "transaction input data"
10
10
  const GAS_PER_NON_ZERO_BYTE = 16
@@ -1,7 +1,7 @@
1
1
  import assert from 'minimalistic-assert'
2
2
 
3
3
  import { isForwarderContractCached } from './eth-like-util.js'
4
- import { fetchGasLimit, resolveDefaultTxInput } from './gas-estimation.js'
4
+ import { EXTRA_PERCENTAGE, fetchGasLimit, resolveDefaultTxInput } from './gas-estimation.js'
5
5
  import { getFeeFactory } from './get-fee.js'
6
6
  import { getNftArguments } from './nft-utils.js'
7
7
 
@@ -13,19 +13,40 @@ const FIXED_TRANSFER_GAS_LIMIT_ASSETS = new Set([
13
13
  'geminidollar',
14
14
  ])
15
15
 
16
- async function resolveExtraPercentage({ asset, toAddress }) {
16
+ const UNKNOWN_ADDRESS_EXTRA_PERCENTAGE = {
17
+ usdt_bsc_ddedf0f8: 80,
18
+ }
19
+
20
+ export async function resolveExtraPercentage({ asset, fromAddress, toAddress }) {
21
+ if (asset.baseAsset.estimateL1DataFee) {
22
+ return 100
23
+ }
24
+
17
25
  const isToken = asset.name !== asset.baseAsset.name
26
+
27
+ const isFixedGasLimitToken = isToken && FIXED_TRANSFER_GAS_LIMIT_ASSETS.has(asset.name)
28
+
29
+ if (isFixedGasLimitToken) {
30
+ return 0
31
+ }
32
+
18
33
  // calling forwarder contracts with a bumped gas limit causes 'Out Of Gas' error on chain
19
34
  const hasForwarderContract =
20
35
  !isToken && toAddress ? await isForwarderContractCached({ asset, address: toAddress }) : false
21
36
 
22
- return asset.baseAsset.estimateL1DataFee
23
- ? 100
24
- : (isToken && FIXED_TRANSFER_GAS_LIMIT_ASSETS.has(asset.name)) || hasForwarderContract
25
- ? 0
26
- : undefined
37
+ if (hasForwarderContract) {
38
+ return 0
39
+ }
40
+
41
+ if (!fromAddress || !toAddress) {
42
+ return UNKNOWN_ADDRESS_EXTRA_PERCENTAGE[asset.name] ?? EXTRA_PERCENTAGE
43
+ }
44
+
45
+ return EXTRA_PERCENTAGE
27
46
  }
28
47
 
48
+ const ARBITRARY_ADDRESS = '0xffffffffffffffffffffffffffffffffffffffff'
49
+
29
50
  const getFeeAsyncFactory = ({
30
51
  assetClientInterface,
31
52
  gasLimit: defaultGasLimit,
@@ -37,8 +58,8 @@ const getFeeAsyncFactory = ({
37
58
  return async ({
38
59
  nft,
39
60
  asset,
40
- fromAddress = '0xffffffffffffffffffffffffffffffffffffffff', // sending from a random address
41
- toAddress = '0xffffffffffffffffffffffffffffffffffffffff', // sending to a random address,
61
+ fromAddress: providedFromAddress,
62
+ toAddress: providedToAddress,
42
63
  amount,
43
64
  bip70,
44
65
  txInput: txInputPram,
@@ -49,16 +70,24 @@ const getFeeAsyncFactory = ({
49
70
  gasLimit: providedGasLimit,
50
71
  isRbfAllowed = true, // Destkop, isRbfAllowed=true when advanced panel is on
51
72
  }) => {
73
+ const fromAddress = providedFromAddress || ARBITRARY_ADDRESS // sending from a random address
74
+ const toAddress = providedToAddress || ARBITRARY_ADDRESS // sending to a random address,
75
+
52
76
  const resolveGasLimit = async () => {
53
77
  if (nft) {
54
78
  return getNftArguments({ asset, nft, fromAddress, toAddress })
55
79
  }
56
80
 
57
81
  if (!amount) amount = asset.currency.ZERO
58
- const extraPercentage = await resolveExtraPercentage({ asset, toAddress })
59
82
  const txInput = txInputPram || resolveDefaultTxInput({ asset, toAddress, amount })
60
83
  if (providedGasLimit) return { gasLimit: providedGasLimit, txInput }
61
84
 
85
+ const extraPercentage = await resolveExtraPercentage({
86
+ asset,
87
+ fromAddress: providedFromAddress,
88
+ toAddress: providedToAddress,
89
+ })
90
+
62
91
  const gasLimit = await fetchGasLimit({
63
92
  asset,
64
93
  fromAddress,