@exodus/ethereum-lib 2.27.0-alpha.0 → 3.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-lib",
3
- "version": "2.27.0-alpha.0",
3
+ "version": "3.0.1",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -15,19 +15,31 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@exodus/asset-lib": "^3.7.1",
18
- "@exodus/assets": "8.0.84",
18
+ "@exodus/assets": "^8.0.84",
19
+ "@exodus/avalanchec-meta": "^1.0.1",
19
20
  "@exodus/basic-utils": "^0.7.0",
20
21
  "@exodus/bip32": "^1.0.0",
22
+ "@exodus/bsc-meta": "^1.0.11",
23
+ "@exodus/ethereum-meta": "^1.0.21",
24
+ "@exodus/ethereumarbnova-meta": "^1.0.2",
25
+ "@exodus/ethereumarbone-meta": "^1.0.2",
26
+ "@exodus/ethereumclassic-meta": "^1.0.1",
27
+ "@exodus/ethereumgoerli-meta": "^1.0.3",
21
28
  "@exodus/ethereumjs-common": "^2.4.0-exodus.6",
22
29
  "@exodus/ethereumjs-tx": "^3.3.0-exodus.6",
23
30
  "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
31
+ "@exodus/fantommainnet-meta": "^1.0.3",
32
+ "@exodus/harmonymainnet-meta": "^1.0.0",
24
33
  "@exodus/key-utils": "^1.0.0",
34
+ "@exodus/matic-meta": "^1.0.8",
25
35
  "@exodus/models": "^8.10.4",
36
+ "@exodus/optimism-meta": "^1.0.0",
37
+ "@exodus/rootstock-meta": "^1.0.2",
26
38
  "@exodus/solidity-contract": "^1.1.3",
27
39
  "base-x": "^3.0.2",
28
40
  "lodash": "^4.17.15",
29
41
  "ms": "^2.1.1",
30
42
  "reselect": "~3.0.1"
31
43
  },
32
- "gitHead": "3241be77078ca4bf456bd7b2e8f3fe545142c92e"
44
+ "gitHead": "906980b1006ee7a1282ab78b02c2c9510b0e86f4"
33
45
  }
package/src/abi/index.js CHANGED
@@ -14,7 +14,6 @@ import maticStakingManager from './matic-staking-manager'
14
14
  import fantomSfc from './fantom-sfc'
15
15
  import ensRegistry from './ens-registry'
16
16
  import ensResolver from './ens-resolver'
17
- import optimismGasOracle from './optimism-gas-oracle'
18
17
 
19
18
  export default {
20
19
  ant,
@@ -33,5 +32,4 @@ export default {
33
32
  fantomSfc,
34
33
  ensRegistry,
35
34
  ensResolver,
36
- optimismGasOracle,
37
35
  }
@@ -30,8 +30,6 @@ export default function createContract(address, contractName) {
30
30
  return new SolidityContract(ABI.ensRegistry, address, true)
31
31
  case 'erc721':
32
32
  return new SolidityContract(ABI.erc721, address, true)
33
- case 'optimismGasOracle':
34
- return new SolidityContract(ABI.optimismGasOracle, address, true)
35
33
  default:
36
34
  return SolidityContract.erc20(address)
37
35
  }
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/avalanchec-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -16,5 +16,5 @@ export default new FeeData({
16
16
  tipGasPrice: '4 nAVAX',
17
17
  },
18
18
  mainKey: 'gasPrice',
19
- currency: assets.avalanchec.currency,
19
+ currency: asset.currency,
20
20
  })
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/bsc-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -12,5 +12,5 @@ export default new FeeData({
12
12
  eip1559Enabled: false,
13
13
  },
14
14
  mainKey: 'gasPrice',
15
- currency: assets.bsc.currency,
15
+ currency: asset.currency,
16
16
  })
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/ethereum-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -17,5 +17,5 @@ export default new FeeData({
17
17
  rbfEnabled: true,
18
18
  },
19
19
  mainKey: 'gasPrice',
20
- currency: assets.ethereum.currency,
20
+ currency: asset.currency,
21
21
  })
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/ethereumarbnova-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -12,5 +12,5 @@ export default new FeeData({
12
12
  eip1559Enabled: false,
13
13
  },
14
14
  mainKey: 'gasPrice',
15
- currency: assets.ethereumarbnova.currency,
15
+ currency: asset.currency,
16
16
  })
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/ethereumarbone-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -12,5 +12,5 @@ export default new FeeData({
12
12
  eip1559Enabled: false,
13
13
  },
14
14
  mainKey: 'gasPrice',
15
- currency: assets.ethereumarbone.currency,
15
+ currency: asset.currency,
16
16
  })
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/ethereumclassic-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -9,5 +9,5 @@ export default new FeeData({
9
9
  eip1559Enabled: false,
10
10
  },
11
11
  mainKey: 'gasPrice',
12
- currency: assets.ethereumclassic.currency,
12
+ currency: asset.currency,
13
13
  })
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/ethereumgoerli-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -16,5 +16,5 @@ export default new FeeData({
16
16
  eip1559Enabled: true,
17
17
  },
18
18
  mainKey: 'gasPrice',
19
- currency: assets.ethereumgoerli.currency,
19
+ currency: asset.currency,
20
20
  })
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/fantommainnet-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -13,5 +13,5 @@ export default new FeeData({
13
13
  eip1559Enabled: false,
14
14
  },
15
15
  mainKey: 'gasPrice',
16
- currency: assets.fantommainnet.currency,
16
+ currency: asset.currency,
17
17
  })
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/harmonymainnet-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -12,5 +12,5 @@ export default new FeeData({
12
12
  eip1559Enabled: false,
13
13
  },
14
14
  mainKey: 'gasPrice',
15
- currency: assets.harmonymainnet.currency,
15
+ currency: asset.currency,
16
16
  })
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/optimism-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -12,5 +12,5 @@ export default new FeeData({
12
12
  eip1559Enabled: false,
13
13
  },
14
14
  mainKey: 'gasPrice',
15
- currency: assets.optimism.currency,
15
+ currency: asset.currency,
16
16
  })
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/matic-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -15,5 +15,5 @@ export default new FeeData({
15
15
  eip1559Enabled: true,
16
16
  },
17
17
  mainKey: 'gasPrice',
18
- currency: assets.matic.currency,
18
+ currency: asset.currency,
19
19
  })
@@ -1,5 +1,5 @@
1
1
  import { FeeData } from '@exodus/asset-lib'
2
- import assets from '@exodus/assets'
2
+ import { asset } from '@exodus/rootstock-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
@@ -12,5 +12,5 @@ export default new FeeData({
12
12
  eip1559Enabled: false,
13
13
  },
14
14
  mainKey: 'gasPrice',
15
- currency: assets.rootstock.currency,
15
+ currency: asset.currency,
16
16
  })
@@ -2,4 +2,3 @@ export { default as createUnsignedTx } from './create-unsigned-tx'
2
2
  export { default as parseUnsignedTx } from './parse-unsigned-tx'
3
3
  export { default as signUnsignedTx } from './sign-unsigned-tx'
4
4
  export { default as createAndSignTx } from './create-and-sign-tx'
5
- export { default as convertUnsignedTx } from './convert-unsigned-tx'
@@ -36,7 +36,6 @@ export default function parseUnsignedTx(
36
36
  }
37
37
 
38
38
  return {
39
- asset,
40
39
  to,
41
40
  amount,
42
41
  fee,
@@ -1,12 +1,52 @@
1
1
  /* @flow */
2
+ import { Transaction, FeeMarketEIP1559Transaction } from '@exodus/ethereumjs-tx'
3
+ import Common from '@exodus/ethereumjs-common'
4
+
2
5
  import type { UnsignedTransaction, SignedTransaction } from '@exodus/models/lib/types'
3
- import convertUnsignedTx from './convert-unsigned-tx'
6
+ import { CUSTOM_CHAINS } from '../constants'
4
7
 
5
8
  export default function signUnsignedTx(
6
9
  unsignedTx: UnsignedTransaction,
7
10
  privateKey: Buffer
8
11
  ): SignedTransaction {
9
- const tx = convertUnsignedTx(unsignedTx)
12
+ const {
13
+ txData: { gasPrice, tipGasPrice: maxPriorityFeePerGas, chainId: chain, ...txData },
14
+ txMeta: { eip1559Enabled },
15
+ } = unsignedTx
16
+
17
+ let tx
18
+ /*
19
+ To assemble an EIP 1559 tx,
20
+ both `tipGasPrice` and `eip` must have been set in the input object used to build `unsignedTx`.
21
+ Whether bsc will support EIP 1559 is unknown.
22
+ So we must prevent building accidentally an EIP1559 tx on bsc if tipGasPrice is set
23
+ `eip` will be set with s corresponding feature flag in the wallet
24
+ */
25
+ if (maxPriorityFeePerGas && eip1559Enabled) {
26
+ tx = FeeMarketEIP1559Transaction.fromTxData(
27
+ {
28
+ maxFeePerGas: gasPrice,
29
+ maxPriorityFeePerGas,
30
+ type: '0x02', // https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx#gas-fee-market-transactions-eip-1559,
31
+ ...txData,
32
+ },
33
+ {
34
+ common: new Common({
35
+ chain,
36
+ hardfork: 'london',
37
+ customChains: CUSTOM_CHAINS,
38
+ eips: [1559],
39
+ }),
40
+ }
41
+ )
42
+ } else {
43
+ // Legacy tx
44
+ tx = Transaction.fromTxData(
45
+ { gasPrice, ...txData },
46
+ { common: Common.custom({ chainId: chain }) }
47
+ )
48
+ }
49
+
10
50
  const signedTx = tx.sign(privateKey)
11
51
 
12
52
  // serialize and get txId
@@ -1,6 +1,5 @@
1
1
  import baseX from 'base-x'
2
2
  import * as ethUtil from '@exodus/ethereumjs-util'
3
- import assets from '@exodus/assets'
4
3
  import { ETHEREUM_LIKE_ASSETS, ETHEREUM_LIKE_TOKEN_TYPES } from '../constants'
5
4
  import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs-tx'
6
5
  import { uniq } from 'lodash'
@@ -22,7 +21,10 @@ export const isRootstockToken = (asset) => asset.assetType === 'RSK_ERC20'
22
21
 
23
22
  // All ethereum-like tokens
24
23
  export const isEthereumLikeToken = (asset) => ETHEREUM_LIKE_TOKEN_TYPES.includes(asset.assetType)
25
- export const isEthereumLikeTokenByName = (assetName) => isEthereumLikeToken(assets[assetName])
24
+ // @deprecated
25
+ export const isEthereumLikeTokenByName = (assetName) => {
26
+ throw new Error('Please use isEthereumLikeToken() instead')
27
+ }
26
28
  export const isToken = isEthereumLikeToken
27
29
 
28
30
  // All ethereum-like assets (native coins)
@@ -31,7 +33,10 @@ export const isEthereumLikeAssetByName = (assetName) => ETHEREUM_LIKE_ASSETS.inc
31
33
 
32
34
  // All ethereum-like assets and tokens
33
35
  export const isEthereumLike = (asset) => ETHEREUM_LIKE_ASSETS.includes(asset.baseAsset.name)
34
- export const isEthereumLikeByName = (assetName) => isEthereumLike(assets[assetName])
36
+ // @deprecated
37
+ export const isEthereumLikeByName = (assetName) => {
38
+ throw new Error('Please use isEthereumLike() instead')
39
+ }
35
40
 
36
41
  export function buffer2currency({ asset, value }) {
37
42
  return asset.currency.baseUnit(base10.encode(value)).toDefault()
@@ -56,9 +61,9 @@ export function normalizeTxId(txId: string): string {
56
61
  else return '0x' + txId
57
62
  }
58
63
 
64
+ // @deprecated
59
65
  export function getBaseAsset(asset) {
60
- console.log(`calling deprecated function getBaseAsset(${asset.name})`) // Apr. 9th 2021
61
- return isEthereumToken(asset) ? assets.ethereum : asset
66
+ throw new Error('getBaseAsset: this function is no longer supported')
62
67
  }
63
68
 
64
69
  const TRANSACTION_TYPE = 2
@@ -99,6 +104,23 @@ export const isApproveTx = (tx) => tx?.data?.data?.startsWith(APPROVE_METHOD_ID)
99
104
 
100
105
  export const isFeePaymentTx = (tx) => tx?.data?.data?.startsWith(FEE_PAYMENT_PREFIX)
101
106
 
107
+ const customTokensWithRpcBalance = [
108
+ 'saitama_ethereum_5547ffb6',
109
+ 'shiryoinu_ethereum_ff507c93',
110
+ 'volt_bsc_bea66b91',
111
+ 'volt_ethereum_9e0778ce',
112
+ 'elephant_bsc_e879afb1',
113
+ 'posi_bsc_9a2aa8c5',
114
+ 'ampl_ethereum_48428467',
115
+ 'mark_ethereum_0d0c07dd',
116
+ 'floki_bsc_c4112b36',
117
+ 'floki_ethereum_4a3891a6',
118
+ 'drb_bsc_8971f1e2',
119
+ 'move_bsc_4b4012e3',
120
+ 'feg_ethereum_ef42acf0',
121
+ 'feg_bsc_48812e49',
122
+ ]
123
+
102
124
  export const isRpcBalanceAsset = (asset) =>
103
125
  [
104
126
  'bsc',
@@ -114,6 +136,7 @@ export const isRpcBalanceAsset = (asset) =>
114
136
  'fantommainnet',
115
137
  'rootstock',
116
138
  'ethereumarbone',
139
+ ...customTokensWithRpcBalance,
117
140
  ].includes(asset.name) || asset.baseAsset.name === 'rootstock'
118
141
 
119
142
  export const getAssetAddresses = (asset) => {
@@ -121,9 +144,9 @@ export const getAssetAddresses = (asset) => {
121
144
  // Can we unify?
122
145
  const addresses = [
123
146
  asset.contract?.address, // asset in wallets:
124
- asset.contract?.current, // asset in @exodus/assets:
147
+ asset.contract?.current, // asset in @exodus/assets-base:
125
148
  ...(asset.addresses?.previous || []), // asset in wallets:
126
- ...(asset.contract?.previous || []), // asset in @exodus/assets:
149
+ ...(asset.contract?.previous || []), // asset in @exodus/assets-base:
127
150
  ]
128
151
  return uniq(addresses.filter((a) => a && typeof a === 'string'))
129
152
  }
@@ -1,298 +0,0 @@
1
- export default [
2
- {
3
- inputs: [
4
- {
5
- internalType: 'address',
6
- name: '_owner',
7
- type: 'address',
8
- },
9
- ],
10
- stateMutability: 'nonpayable',
11
- type: 'constructor',
12
- },
13
- {
14
- anonymous: false,
15
- inputs: [
16
- {
17
- indexed: false,
18
- internalType: 'uint256',
19
- name: '',
20
- type: 'uint256',
21
- },
22
- ],
23
- name: 'DecimalsUpdated',
24
- type: 'event',
25
- },
26
- {
27
- anonymous: false,
28
- inputs: [
29
- {
30
- indexed: false,
31
- internalType: 'uint256',
32
- name: '',
33
- type: 'uint256',
34
- },
35
- ],
36
- name: 'GasPriceUpdated',
37
- type: 'event',
38
- },
39
- {
40
- anonymous: false,
41
- inputs: [
42
- {
43
- indexed: false,
44
- internalType: 'uint256',
45
- name: '',
46
- type: 'uint256',
47
- },
48
- ],
49
- name: 'L1BaseFeeUpdated',
50
- type: 'event',
51
- },
52
- {
53
- anonymous: false,
54
- inputs: [
55
- {
56
- indexed: false,
57
- internalType: 'uint256',
58
- name: '',
59
- type: 'uint256',
60
- },
61
- ],
62
- name: 'OverheadUpdated',
63
- type: 'event',
64
- },
65
- {
66
- anonymous: false,
67
- inputs: [
68
- {
69
- indexed: true,
70
- internalType: 'address',
71
- name: 'previousOwner',
72
- type: 'address',
73
- },
74
- {
75
- indexed: true,
76
- internalType: 'address',
77
- name: 'newOwner',
78
- type: 'address',
79
- },
80
- ],
81
- name: 'OwnershipTransferred',
82
- type: 'event',
83
- },
84
- {
85
- anonymous: false,
86
- inputs: [
87
- {
88
- indexed: false,
89
- internalType: 'uint256',
90
- name: '',
91
- type: 'uint256',
92
- },
93
- ],
94
- name: 'ScalarUpdated',
95
- type: 'event',
96
- },
97
- {
98
- inputs: [],
99
- name: 'decimals',
100
- outputs: [
101
- {
102
- internalType: 'uint256',
103
- name: '',
104
- type: 'uint256',
105
- },
106
- ],
107
- stateMutability: 'view',
108
- type: 'function',
109
- },
110
- {
111
- inputs: [],
112
- name: 'gasPrice',
113
- outputs: [
114
- {
115
- internalType: 'uint256',
116
- name: '',
117
- type: 'uint256',
118
- },
119
- ],
120
- stateMutability: 'view',
121
- type: 'function',
122
- },
123
- {
124
- inputs: [
125
- {
126
- internalType: 'bytes',
127
- name: '_data',
128
- type: 'bytes',
129
- },
130
- ],
131
- name: 'getL1Fee',
132
- outputs: [
133
- {
134
- internalType: 'uint256',
135
- name: '',
136
- type: 'uint256',
137
- },
138
- ],
139
- stateMutability: 'view',
140
- type: 'function',
141
- },
142
- {
143
- inputs: [
144
- {
145
- internalType: 'bytes',
146
- name: '_data',
147
- type: 'bytes',
148
- },
149
- ],
150
- name: 'getL1GasUsed',
151
- outputs: [
152
- {
153
- internalType: 'uint256',
154
- name: '',
155
- type: 'uint256',
156
- },
157
- ],
158
- stateMutability: 'view',
159
- type: 'function',
160
- },
161
- {
162
- inputs: [],
163
- name: 'l1BaseFee',
164
- outputs: [
165
- {
166
- internalType: 'uint256',
167
- name: '',
168
- type: 'uint256',
169
- },
170
- ],
171
- stateMutability: 'view',
172
- type: 'function',
173
- },
174
- {
175
- inputs: [],
176
- name: 'overhead',
177
- outputs: [
178
- {
179
- internalType: 'uint256',
180
- name: '',
181
- type: 'uint256',
182
- },
183
- ],
184
- stateMutability: 'view',
185
- type: 'function',
186
- },
187
- {
188
- inputs: [],
189
- name: 'owner',
190
- outputs: [
191
- {
192
- internalType: 'address',
193
- name: '',
194
- type: 'address',
195
- },
196
- ],
197
- stateMutability: 'view',
198
- type: 'function',
199
- },
200
- {
201
- inputs: [],
202
- name: 'renounceOwnership',
203
- outputs: [],
204
- stateMutability: 'nonpayable',
205
- type: 'function',
206
- },
207
- {
208
- inputs: [],
209
- name: 'scalar',
210
- outputs: [
211
- {
212
- internalType: 'uint256',
213
- name: '',
214
- type: 'uint256',
215
- },
216
- ],
217
- stateMutability: 'view',
218
- type: 'function',
219
- },
220
- {
221
- inputs: [
222
- {
223
- internalType: 'uint256',
224
- name: '_decimals',
225
- type: 'uint256',
226
- },
227
- ],
228
- name: 'setDecimals',
229
- outputs: [],
230
- stateMutability: 'nonpayable',
231
- type: 'function',
232
- },
233
- {
234
- inputs: [
235
- {
236
- internalType: 'uint256',
237
- name: '_gasPrice',
238
- type: 'uint256',
239
- },
240
- ],
241
- name: 'setGasPrice',
242
- outputs: [],
243
- stateMutability: 'nonpayable',
244
- type: 'function',
245
- },
246
- {
247
- inputs: [
248
- {
249
- internalType: 'uint256',
250
- name: '_baseFee',
251
- type: 'uint256',
252
- },
253
- ],
254
- name: 'setL1BaseFee',
255
- outputs: [],
256
- stateMutability: 'nonpayable',
257
- type: 'function',
258
- },
259
- {
260
- inputs: [
261
- {
262
- internalType: 'uint256',
263
- name: '_overhead',
264
- type: 'uint256',
265
- },
266
- ],
267
- name: 'setOverhead',
268
- outputs: [],
269
- stateMutability: 'nonpayable',
270
- type: 'function',
271
- },
272
- {
273
- inputs: [
274
- {
275
- internalType: 'uint256',
276
- name: '_scalar',
277
- type: 'uint256',
278
- },
279
- ],
280
- name: 'setScalar',
281
- outputs: [],
282
- stateMutability: 'nonpayable',
283
- type: 'function',
284
- },
285
- {
286
- inputs: [
287
- {
288
- internalType: 'address',
289
- name: 'newOwner',
290
- type: 'address',
291
- },
292
- ],
293
- name: 'transferOwnership',
294
- outputs: [],
295
- stateMutability: 'nonpayable',
296
- type: 'function',
297
- },
298
- ]
@@ -1,47 +0,0 @@
1
- /* @flow */
2
- import { Transaction, FeeMarketEIP1559Transaction } from '@exodus/ethereumjs-tx'
3
- import Common from '@exodus/ethereumjs-common'
4
-
5
- import type { UnsignedTransaction } from '@exodus/models/lib/types'
6
- import { CUSTOM_CHAINS } from '../constants'
7
-
8
- export default function convertUnsignedTx(unsignedTx: UnsignedTransaction) {
9
- const {
10
- txData: { gasPrice, tipGasPrice: maxPriorityFeePerGas, chainId: chain, ...txData },
11
- txMeta: { eip1559Enabled },
12
- } = unsignedTx
13
-
14
- let tx
15
- /*
16
- To assemble an EIP 1559 tx,
17
- both `tipGasPrice` and `eip` must have been set in the input object used to build `unsignedTx`.
18
- Whether bsc will support EIP 1559 is unknown.
19
- So we must prevent building accidentally an EIP1559 tx on bsc if tipGasPrice is set
20
- `eip` will be set with s corresponding feature flag in the wallet
21
- */
22
- if (maxPriorityFeePerGas && eip1559Enabled) {
23
- tx = FeeMarketEIP1559Transaction.fromTxData(
24
- {
25
- maxFeePerGas: gasPrice,
26
- maxPriorityFeePerGas,
27
- type: '0x02', // https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx#gas-fee-market-transactions-eip-1559,
28
- ...txData,
29
- },
30
- {
31
- common: new Common({
32
- chain,
33
- hardfork: 'london',
34
- customChains: CUSTOM_CHAINS,
35
- eips: [1559],
36
- }),
37
- }
38
- )
39
- } else {
40
- // Legacy tx
41
- tx = Transaction.fromTxData(
42
- { gasPrice, ...txData },
43
- { common: Common.custom({ chainId: chain }) }
44
- )
45
- }
46
- return tx
47
- }