@exodus/ethereum-api 2.1.6 → 2.2.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/package.json +3 -3
- package/src/eth-like-util.js +32 -35
- package/src/exodus-eth-server/index.js +13 -0
- package/src/gas-estimation.js +6 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Ethereum Api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "Exodus Movement, Inc.",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"access": "restricted"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@exodus/ethereum-lib": "^2.
|
|
13
|
+
"@exodus/ethereum-lib": "^2.4.1",
|
|
14
14
|
"@exodus/simple-retry": "^0.0.6",
|
|
15
15
|
"fetchival": "0.3.3",
|
|
16
16
|
"lodash": "^4.17.11",
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"url-join": "4.0.0",
|
|
21
21
|
"ws": "6.1.0"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "5a78637356487708e369f002616fac2963c6db94"
|
|
24
24
|
}
|
package/src/eth-like-util.js
CHANGED
|
@@ -1,58 +1,55 @@
|
|
|
1
1
|
import { get } from 'lodash'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { normalizeTxId } from '@exodus/ethereum-lib'
|
|
3
|
+
import { eth, serverMap, getServer } from './exodus-eth-server'
|
|
4
|
+
|
|
5
|
+
// Mobile only.
|
|
6
|
+
// Behavior is buggy, because the default server used is ethereum.
|
|
7
|
+
// We should refactor mobile to pass 'asset' instead of 'assetName' so that we can use 'isContractAddress'. But that would touch many assets.
|
|
8
|
+
export async function isContract(baseAssetName, address) {
|
|
9
|
+
const server = serverMap[baseAssetName] || eth
|
|
6
10
|
return server.isContract(address)
|
|
7
11
|
}
|
|
8
12
|
|
|
13
|
+
export async function isContractAddress({ asset, address }) {
|
|
14
|
+
return getServer(asset).isContract(address)
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
export async function getNonce({ asset, address, tag = 'latest' }) {
|
|
10
|
-
|
|
11
|
-
const server = asset.name === 'ethereumclassic' ? etc : asset.name === 'quorum' ? quorum : eth
|
|
18
|
+
const server = getServer(asset)
|
|
12
19
|
const nonce = await server.getTransactionCount(address, tag)
|
|
13
20
|
return parseInt(nonce, 16)
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
export async function estimateGas({ asset, ...args }) {
|
|
17
|
-
|
|
18
|
-
return server.estimateGas(args)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const fetchEthereumBalance = async (address, balanceField = 'value') => {
|
|
22
|
-
const balances = await eth.getBalance(address)
|
|
23
|
-
return get(balances, ['confirmed', balanceField], '0')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const fetchEthereumClassicBalance = async (address) => {
|
|
27
|
-
const balances = await etc.getBalance(address)
|
|
28
|
-
return get(balances, 'confirmed.value', '0')
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const fetchQuorumBalance = async (address, balanceField = 'value') => {
|
|
32
|
-
const balances = await quorum.getBalance(address)
|
|
33
|
-
return get(balances, ['confirmed', balanceField], '0')
|
|
24
|
+
return getServer(asset).estimateGas(args)
|
|
34
25
|
}
|
|
35
26
|
|
|
36
27
|
// Only Ethereum and Ethereumclassic, not ERC20
|
|
37
28
|
export async function getBalance({ asset, address }) {
|
|
38
|
-
|
|
39
|
-
asset.name
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
: fetchEthereumBalance
|
|
44
|
-
return _getBalance(address)
|
|
29
|
+
if (!['ethereum', 'ethereumclassic', 'quorum'].includes(asset.name))
|
|
30
|
+
throw new Error(`unsupported asset ${asset.name}`)
|
|
31
|
+
const server = getServer(asset)
|
|
32
|
+
const balances = await server.getBalance(address)
|
|
33
|
+
return get(balances, ['confirmed', 'value'], '0')
|
|
45
34
|
}
|
|
46
35
|
|
|
47
36
|
// Only Ethereum ERC20, not Ethereumclassic
|
|
48
37
|
export async function getTokenBalance({ asset, address }) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
if (!['ethereum', 'quorum'].includes(asset.baseAsset.name))
|
|
39
|
+
throw new Error(`unsupported base asset ${asset.baseAsset.name}`)
|
|
40
|
+
const server = getServer(asset)
|
|
41
|
+
const balances = await server.getBalance(address)
|
|
42
|
+
return get(balances, ['confirmed', asset.contract.address.toLowerCase()], '0')
|
|
52
43
|
}
|
|
53
44
|
|
|
54
45
|
// Returns function for supplied asset
|
|
55
46
|
export function sendRawTransaction(asset) {
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
return getServer(asset).sendRawTransaction
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function transactionExists({ asset, txId }) {
|
|
51
|
+
const server = getServer(asset)
|
|
52
|
+
txId = normalizeTxId(txId)
|
|
53
|
+
const txResult = await server.getTransactionByHash(txId)
|
|
54
|
+
return txResult && txResult.hash === txId
|
|
58
55
|
}
|
|
@@ -9,3 +9,16 @@ const EXODUS_QUORUM_SERVER_URL = 'https://geth-quorum.a.exodus.io/wallet/v1'
|
|
|
9
9
|
export const eth = create(EXODUS_ETH_SERVER_URL)
|
|
10
10
|
export const etc = create(EXODUS_ETC_SERVER_URL)
|
|
11
11
|
export const quorum = create(EXODUS_QUORUM_SERVER_URL)
|
|
12
|
+
|
|
13
|
+
export const serverMap = {
|
|
14
|
+
ethereum: eth,
|
|
15
|
+
ethereumclassic: etc,
|
|
16
|
+
quorum,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getServer(asset) {
|
|
20
|
+
const baseAssetName = asset.baseAsset.name
|
|
21
|
+
const server = serverMap[baseAssetName]
|
|
22
|
+
if (!server) throw new Error(`unsupported base asset ${baseAssetName}`)
|
|
23
|
+
return server
|
|
24
|
+
}
|
package/src/gas-estimation.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BN from 'bn.js'
|
|
2
2
|
import * as ethUtil from 'ethereumjs-util'
|
|
3
|
-
import { currency2buffer, isEthereumToken
|
|
4
|
-
import { estimateGas,
|
|
3
|
+
import { currency2buffer, isEthereumToken } from '@exodus/ethereum-lib'
|
|
4
|
+
import { estimateGas, isContractAddress } from './eth-like-util'
|
|
5
5
|
|
|
6
6
|
const EXTRA_PERCENTAGE = 20
|
|
7
7
|
|
|
@@ -46,17 +46,18 @@ export async function fetchGasLimit({
|
|
|
46
46
|
extraPercentage,
|
|
47
47
|
}) {
|
|
48
48
|
if (!amount) amount = asset.currency.ZERO
|
|
49
|
-
if (!feeData.gasPrice) feeData.gasPrice =
|
|
49
|
+
if (!feeData.gasPrice) feeData.gasPrice = asset.baseAsset.currency.ZERO
|
|
50
50
|
|
|
51
51
|
const isToken = isEthereumToken(asset)
|
|
52
52
|
if (isToken) {
|
|
53
53
|
txInput = ethUtil.bufferToHex(
|
|
54
54
|
asset.contract.transfer.build(toAddress, amount.toBase().toNumberString())
|
|
55
55
|
)
|
|
56
|
-
amount =
|
|
56
|
+
amount = asset.baseAsset.currency.ZERO
|
|
57
57
|
toAddress = asset.contract.address
|
|
58
58
|
} else if (!isContract) {
|
|
59
|
-
if (isContract === undefined)
|
|
59
|
+
if (isContract === undefined)
|
|
60
|
+
isContract = await isContractAddress({ asset, address: toAddress })
|
|
60
61
|
if (!isContract) return asset.gasLimit
|
|
61
62
|
}
|
|
62
63
|
|