@exodus/ethereum-api 2.25.1 → 2.25.3
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-api",
|
|
3
|
-
"version": "2.25.
|
|
3
|
+
"version": "2.25.3",
|
|
4
4
|
"description": "Ethereum Api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@exodus/models": "^8.7.2"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "5fc9011ce93fad50a48bccb4ab25930dbf7d762b"
|
|
38
38
|
}
|
package/src/gas-estimation.js
CHANGED
|
@@ -5,6 +5,11 @@ import { estimateGas, isContractAddress } from './eth-like-util'
|
|
|
5
5
|
|
|
6
6
|
const EXTRA_PERCENTAGE = 20
|
|
7
7
|
|
|
8
|
+
// 16 gas per non-zero byte (4 gas per zero byte) of "transaction input data"
|
|
9
|
+
const GAS_PER_NON_ZERO_BYTE = 16
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_CONTRACT_GAS_LIMIT = 1e6
|
|
12
|
+
|
|
8
13
|
// Starting with geth v1.9.14, if gasPrice is set for eth_estimateGas call, the call allowance will
|
|
9
14
|
// be calculated with account's balance divided by gasPrice. If user's balance is too low,
|
|
10
15
|
// the gasEstimation will fail. If gasPrice is set to '0x0', the account's balance is not
|
|
@@ -17,7 +22,7 @@ export async function estimateGasLimit(
|
|
|
17
22
|
data: Buffer | string,
|
|
18
23
|
gasPrice?: string = '0x',
|
|
19
24
|
extraPercentage?: number = EXTRA_PERCENTAGE
|
|
20
|
-
): number {
|
|
25
|
+
): Promise<number> {
|
|
21
26
|
const opts = {
|
|
22
27
|
from: fromAddress,
|
|
23
28
|
to: toAddress,
|
|
@@ -51,6 +56,9 @@ export async function fetchGasLimit({
|
|
|
51
56
|
if (!amount) amount = asset.currency.ZERO
|
|
52
57
|
if (!feeData.gasPrice) feeData.gasPrice = asset.baseAsset.currency.ZERO
|
|
53
58
|
|
|
59
|
+
const defaultGasLimit = () =>
|
|
60
|
+
asset.gasLimit + GAS_PER_NON_ZERO_BYTE * ethUtil.toBuffer(txInput).length
|
|
61
|
+
|
|
54
62
|
const _isToken = isToken(asset)
|
|
55
63
|
if (_isToken) {
|
|
56
64
|
txInput = ethUtil.bufferToHex(
|
|
@@ -61,7 +69,7 @@ export async function fetchGasLimit({
|
|
|
61
69
|
} else if (!isContract) {
|
|
62
70
|
if (isContract === undefined)
|
|
63
71
|
isContract = await isContractAddress({ asset, address: toAddress })
|
|
64
|
-
if (!isContract) return
|
|
72
|
+
if (!isContract) return defaultGasLimit()
|
|
65
73
|
}
|
|
66
74
|
|
|
67
75
|
const gasPrice = ethUtil.bufferToHex(currency2buffer(feeData.gasPrice))
|
|
@@ -78,10 +86,14 @@ export async function fetchGasLimit({
|
|
|
78
86
|
)
|
|
79
87
|
} catch (err) {
|
|
80
88
|
if (throwOnError) throw err
|
|
81
|
-
console.
|
|
82
|
-
|
|
89
|
+
console.error('fetchGasLimit error', err)
|
|
90
|
+
|
|
91
|
+
// fallback value for contract case
|
|
92
|
+
if (isContract) return asset.contractGasLimit || DEFAULT_CONTRACT_GAS_LIMIT
|
|
83
93
|
|
|
84
|
-
|
|
94
|
+
// fallback value for rest cases: token.
|
|
95
|
+
return defaultGasLimit()
|
|
96
|
+
}
|
|
85
97
|
}
|
|
86
98
|
|
|
87
99
|
function normalizeAmount(amount) {
|
|
@@ -23,10 +23,21 @@ async function getAssetSymbolFromContract(contractAddress) {
|
|
|
23
23
|
return assetSymbol
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
async function prepareBalanceChanges(
|
|
26
|
+
async function prepareBalanceChanges(
|
|
27
|
+
internalTransactions,
|
|
28
|
+
balanceChanges,
|
|
29
|
+
transactionInput,
|
|
30
|
+
assetName = 'ethereum'
|
|
31
|
+
) {
|
|
32
|
+
const assetNameToSymbolMap = Object.create(null)
|
|
33
|
+
assetNameToSymbolMap['ethereum'] = 'ETH' // Refactor after blowfish integration
|
|
34
|
+
|
|
35
|
+
const asset = assets[assetName]
|
|
27
36
|
const preparedBalanceChanges = [...balanceChanges]
|
|
28
37
|
|
|
29
38
|
const decimals = Object.create(null)
|
|
39
|
+
decimals[assetNameToSymbolMap[asset.name]] = asset.currency.defaultUnit.power // Always have a default asset decimal in map for edge cases
|
|
40
|
+
|
|
30
41
|
const assetSymbols = Object.create(null)
|
|
31
42
|
let contractName
|
|
32
43
|
let isERC721 = false
|
|
@@ -115,7 +126,7 @@ async function tryToDecodeApprovalTransaction(transaction) {
|
|
|
115
126
|
}
|
|
116
127
|
}
|
|
117
128
|
|
|
118
|
-
export async function simulateAndRetrieveSideEffects(transaction) {
|
|
129
|
+
export async function simulateAndRetrieveSideEffects(transaction, assetName) {
|
|
119
130
|
const willSend = []
|
|
120
131
|
const willReceive = []
|
|
121
132
|
|
|
@@ -150,7 +161,8 @@ export async function simulateAndRetrieveSideEffects(transaction) {
|
|
|
150
161
|
const preparedBalanceChanges = await prepareBalanceChanges(
|
|
151
162
|
internalTransactions,
|
|
152
163
|
sender.balanceChanges,
|
|
153
|
-
transaction.data
|
|
164
|
+
transaction.data,
|
|
165
|
+
assetName
|
|
154
166
|
)
|
|
155
167
|
|
|
156
168
|
for (const balanceChange of preparedBalanceChanges) {
|