@exodus/ethereum-lib 0.2.4 → 0.2.8
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": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Ethereum Library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "Exodus Movement, Inc.",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"ethereumjs-tx": "1.3.7",
|
|
17
17
|
"ethereumjs-util": "5.2.0"
|
|
18
18
|
},
|
|
19
|
-
"
|
|
19
|
+
"peerDependencies": {
|
|
20
20
|
"@exodus/assets": "8.0.x"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "fc53854a8e60f021526fa8b6f4ac7fb5ccb0a5a4"
|
|
23
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ethUtil from 'ethereumjs-util'
|
|
2
|
-
import {
|
|
2
|
+
import { isEthereumToken, currency2buffer } from '../utils'
|
|
3
3
|
import { CHAIN_IDS } from '../constants'
|
|
4
4
|
|
|
5
5
|
import type { UnsignedTransaction } from '#/app-models'
|
|
@@ -25,9 +25,9 @@ export default function createUnsignedTx({
|
|
|
25
25
|
|
|
26
26
|
if (!chainId) chainId = CHAIN_IDS[baseAsset.name] // mainnet
|
|
27
27
|
|
|
28
|
-
const
|
|
29
|
-
const to =
|
|
30
|
-
let value = currency2buffer(
|
|
28
|
+
const isToken = isEthereumToken(asset)
|
|
29
|
+
const to = isToken ? asset.contract.addresses.current : address
|
|
30
|
+
let value = currency2buffer(isToken ? baseAsset.currency.ZERO : amount)
|
|
31
31
|
|
|
32
32
|
// TODO: check: present on desktop missing on mobile. This insures we never have a buffer specifying 0.
|
|
33
33
|
// In ETH, a buffer of zero length and a buffer specifying 0 imply different things
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
import * as ethUtil from 'ethereumjs-util'
|
|
3
3
|
import assets from '@exodus/assets'
|
|
4
|
-
import {
|
|
4
|
+
import { isEthereumToken, buffer2currency } from '../utils'
|
|
5
5
|
import { CHAIN_IDS } from '../constants'
|
|
6
6
|
|
|
7
7
|
import type { UnsignedTransaction, ParsedTransaction } from '@exodus/models/lib/types'
|
|
@@ -12,8 +12,8 @@ export default function parseUnsignedTx(unsignedTx: UnsignedTransaction): Parsed
|
|
|
12
12
|
txMeta: { assetName },
|
|
13
13
|
} = unsignedTx
|
|
14
14
|
const asset = assets[assetName]
|
|
15
|
-
const
|
|
16
|
-
const baseAsset =
|
|
15
|
+
const isToken = isEthereumToken(asset)
|
|
16
|
+
const baseAsset = isToken ? assets.ethereum : asset
|
|
17
17
|
|
|
18
18
|
const gasPrice = buffer2currency({ asset: baseAsset, value: txData.gasPrice })
|
|
19
19
|
const gasLimit = ethUtil.bufferToInt(txData.gasLimit)
|
|
@@ -21,7 +21,7 @@ export default function parseUnsignedTx(unsignedTx: UnsignedTransaction): Parsed
|
|
|
21
21
|
let { to, chainId, data } = txData
|
|
22
22
|
let amount
|
|
23
23
|
const fee = gasPrice.mul(gasLimit)
|
|
24
|
-
if (
|
|
24
|
+
if (isToken) {
|
|
25
25
|
const parsed = asset.contract.transfer.parse(data)
|
|
26
26
|
to = parsed.to
|
|
27
27
|
amount = parsed.amount
|
package/src/utils.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import baseX from 'base-x'
|
|
2
2
|
import * as ethUtil from 'ethereumjs-util'
|
|
3
|
+
import assets from '@exodus/assets'
|
|
3
4
|
|
|
4
5
|
const base10 = baseX('0123456789')
|
|
5
6
|
const base16 = baseX('0123456789abcdef')
|
|
6
7
|
|
|
7
|
-
export const
|
|
8
|
+
export const isEthereumToken = (asset) => asset.assetType === 'ETHEREUM_ERC20'
|
|
8
9
|
|
|
9
10
|
export function buffer2currency({ asset, value }) {
|
|
10
11
|
return asset.currency.baseUnit(base10.encode(value)).toDefault()
|
|
@@ -31,3 +32,7 @@ export function normalizeTxId(txId: string): string {
|
|
|
31
32
|
if (txId.startsWith('0x')) return txId
|
|
32
33
|
else return '0x' + txId
|
|
33
34
|
}
|
|
35
|
+
|
|
36
|
+
export function getBaseAsset(asset) {
|
|
37
|
+
return isEthereumToken(asset) ? assets.ethereum : asset
|
|
38
|
+
}
|