@exodus/ethereum-lib 0.2.11 → 1.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": "0.2.11",
3
+ "version": "1.0.1",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -20,5 +20,5 @@
20
20
  "peerDependencies": {
21
21
  "@exodus/assets": "8.0.x"
22
22
  },
23
- "gitHead": "b3be7ab2c2dfba90b30aaaea41027fadb27f3571"
23
+ "gitHead": "a9a7090a6ecf3e29a191e632f2f0ccaef89b5cb2"
24
24
  }
@@ -1,11 +1,12 @@
1
1
  import SolidityContract from '@exodus/solidity-contract'
2
- // import createContractErc20 from './erc20'
3
- import ABI from '../abi'
2
+ // import ABI from '../abi'
4
3
 
5
4
  export default function createContract(address, assetName) {
6
5
  switch (assetName) {
7
- case 'dai':
8
- return new SolidityContract(ABI.dai, address)
6
+ // case 'dai':
7
+ // return new SolidityContract(ABI.dai, address)
8
+ // case 'cdai':
9
+ // return new SolidityContract(ABI.cdai, address)
9
10
  default:
10
11
  return SolidityContract.erc20(address)
11
12
  }
@@ -1,20 +1,17 @@
1
1
  /* @flow */
2
2
  import * as ethUtil from 'ethereumjs-util'
3
- import assets from '@exodus/assets'
4
- import { isEthereumToken, buffer2currency } from '../utils'
3
+ import { isEthereumToken, buffer2currency, getBaseAsset } from '../utils'
5
4
  import { CHAIN_IDS } from '../constants'
6
5
 
7
6
  import type { UnsignedTransaction, ParsedTransaction } from '@exodus/models/lib/types'
8
7
 
9
- export default function parseUnsignedTx(unsignedTx: UnsignedTransaction): ParsedTransaction {
10
- const {
11
- txData,
12
- txMeta: { assetName },
13
- } = unsignedTx
14
- const asset = assets[assetName]
8
+ export default function parseUnsignedTx(
9
+ asset: Object,
10
+ unsignedTx: UnsignedTransaction
11
+ ): ParsedTransaction {
12
+ const { txData } = unsignedTx
15
13
  const isToken = isEthereumToken(asset)
16
- const baseAsset = isToken ? assets.ethereum : asset
17
-
14
+ const baseAsset = getBaseAsset(asset)
18
15
  const gasPrice = buffer2currency({ asset: baseAsset, value: txData.gasPrice })
19
16
  const gasLimit = ethUtil.bufferToInt(txData.gasLimit)
20
17
 
@@ -22,23 +19,27 @@ export default function parseUnsignedTx(unsignedTx: UnsignedTransaction): Parsed
22
19
  let amount
23
20
  const fee = gasPrice.mul(gasLimit)
24
21
  if (isToken) {
25
- const parsed = asset.contract.transfer.parse(data)
26
- to = parsed.to
27
- amount = parsed.amount
22
+ const { method, values } = asset.contract.decodeInput(data)
23
+ if (method === 'transfer' || method === 'approve') {
24
+ to = values[0]
25
+ amount = asset.currency.baseUnit(values[1]).toDefault()
26
+ } else {
27
+ to = values[0]
28
+ amount = asset.currency.ZERO
29
+ }
28
30
  } else {
29
- amount = buffer2currency({ asset: baseAsset, value: txData.value })
31
+ amount = buffer2currency({ asset, value: txData.value })
30
32
  }
31
33
 
32
34
  if (chainId !== CHAIN_IDS[baseAsset.name]) {
33
- throw new Error(`invalid chainId ${chainId} for asset ${assetName}`)
35
+ throw new Error(`invalid chainId ${chainId} for asset ${asset.name}`)
34
36
  }
35
37
 
36
38
  return {
37
- baseAsset,
38
39
  asset,
39
- from: null, // TODO: how?
40
40
  to,
41
41
  amount,
42
42
  fee,
43
+ from: null, // TODO: how?
43
44
  }
44
45
  }