edge-currency-accountbased 0.7.72

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +713 -0
  2. package/LICENSE +29 -0
  3. package/README.md +63 -0
  4. package/index.js +3 -0
  5. package/lib/binance/bnbEngine.js +591 -0
  6. package/lib/binance/bnbInfo.js +43 -0
  7. package/lib/binance/bnbPlugin.js +168 -0
  8. package/lib/binance/bnbSchema.js +83 -0
  9. package/lib/binance/bnbTypes.js +39 -0
  10. package/lib/common/engine.js +918 -0
  11. package/lib/common/plugin.js +152 -0
  12. package/lib/common/schema.js +108 -0
  13. package/lib/common/types.js +85 -0
  14. package/lib/common/utils.js +378 -0
  15. package/lib/eos/eosEngine.js +1216 -0
  16. package/lib/eos/eosInfo.js +98 -0
  17. package/lib/eos/eosPlugin.js +314 -0
  18. package/lib/eos/eosSchema.js +190 -0
  19. package/lib/eos/eosTypes.js +88 -0
  20. package/lib/eos/telosInfo.js +94 -0
  21. package/lib/eos/waxInfo.js +95 -0
  22. package/lib/ethereum/etcInfo.js +121 -0
  23. package/lib/ethereum/ethEngine.js +832 -0
  24. package/lib/ethereum/ethInfo.js +1300 -0
  25. package/lib/ethereum/ethMiningFees.js +157 -0
  26. package/lib/ethereum/ethNetwork.js +2195 -0
  27. package/lib/ethereum/ethPlugin.js +377 -0
  28. package/lib/ethereum/ethSchema.js +61 -0
  29. package/lib/ethereum/ethTypes.js +461 -0
  30. package/lib/ethereum/ftminfo.js +102 -0
  31. package/lib/ethereum/rskInfo.js +101 -0
  32. package/lib/fio/fioConst.js +38 -0
  33. package/lib/fio/fioEngine.js +1250 -0
  34. package/lib/fio/fioError.js +38 -0
  35. package/lib/fio/fioInfo.js +72 -0
  36. package/lib/fio/fioPlugin.js +486 -0
  37. package/lib/fio/fioSchema.js +56 -0
  38. package/lib/index.js +44 -0
  39. package/lib/pluginError.js +32 -0
  40. package/lib/react-native/edge-currency-accountbased.js +239635 -0
  41. package/lib/react-native/edge-currency-accountbased.js.map +1 -0
  42. package/lib/react-native-io.js +41 -0
  43. package/lib/stellar/stellarEngine.js +563 -0
  44. package/lib/stellar/stellarInfo.js +37 -0
  45. package/lib/stellar/stellarPlugin.js +215 -0
  46. package/lib/stellar/stellarSchema.js +54 -0
  47. package/lib/stellar/stellarTypes.js +66 -0
  48. package/lib/tezos/tezosEngine.js +497 -0
  49. package/lib/tezos/tezosInfo.js +60 -0
  50. package/lib/tezos/tezosPlugin.js +174 -0
  51. package/lib/tezos/tezosTypes.js +110 -0
  52. package/lib/xrp/xrpEngine.js +583 -0
  53. package/lib/xrp/xrpInfo.js +47 -0
  54. package/lib/xrp/xrpPlugin.js +229 -0
  55. package/lib/xrp/xrpSchema.js +74 -0
  56. package/lib/xrp/xrpTypes.js +38 -0
  57. package/package.json +139 -0
  58. package/postinstall.sh +7 -0
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Created by paul on 8/26/17.
3
+ *
4
+ */
5
+
6
+ import { bns } from 'biggystring'
7
+
8
+
9
+ import { normalizeAddress } from '../common/utils.js'
10
+
11
+
12
+
13
+
14
+
15
+
16
+ export const ES_FEE_LOW = 'low'
17
+ export const ES_FEE_STANDARD = 'standard'
18
+ export const ES_FEE_HIGH = 'high'
19
+ export const ES_FEE_CUSTOM = 'custom'
20
+
21
+ const WEI_MULTIPLIER = '1000000000'
22
+
23
+ export function calcMiningFee(
24
+ spendInfo,
25
+ networkFees,
26
+ currencyInfo
27
+ ) {
28
+ let useDefaults = true
29
+ if (
30
+ spendInfo.spendTargets &&
31
+ spendInfo.spendTargets.length &&
32
+ spendInfo.spendTargets[0].publicAddress
33
+ ) {
34
+ const { customNetworkFee } = spendInfo || {}
35
+ if (spendInfo.networkFeeOption === ES_FEE_CUSTOM && customNetworkFee) {
36
+ const { gasLimit, gasPrice } = customNetworkFee
37
+ const {
38
+ gasLimit: { minGasLimit },
39
+ gasPrice: { minGasPrice }
40
+ } = currencyInfo.defaultSettings.otherSettings.defaultNetworkFees.default
41
+ const minGasPriceGwei = bns.div(minGasPrice, WEI_MULTIPLIER)
42
+ if (
43
+ bns.lt(gasLimit, minGasLimit) ||
44
+ bns.lt(gasPrice, minGasPriceGwei) ||
45
+ isNaN(gasLimit) ||
46
+ isNaN(gasPrice) ||
47
+ /^\s*$/.test(gasLimit) ||
48
+ /^\s*$/.test(gasPrice)
49
+ ) {
50
+ const e = new Error(
51
+ `Gas Limit: ${minGasLimit} Gas Price (Gwei): ${minGasPriceGwei}`
52
+ )
53
+ e.name = 'ErrorBelowMinimumFee'
54
+ throw e
55
+ }
56
+
57
+ const gasPriceWei = bns.mul(gasPrice, WEI_MULTIPLIER)
58
+ return { gasLimit, gasPrice: gasPriceWei, useDefaults: false }
59
+ }
60
+ const targetAddress = normalizeAddress(
61
+ spendInfo.spendTargets[0].publicAddress
62
+ )
63
+ let networkFeeForGasPrice = networkFees.default
64
+ let networkFeeForGasLimit = networkFees.default
65
+
66
+ if (typeof networkFees[targetAddress] !== 'undefined') {
67
+ networkFeeForGasLimit = networkFees[targetAddress]
68
+ useDefaults = false
69
+ if (typeof networkFeeForGasLimit.gasPrice !== 'undefined') {
70
+ networkFeeForGasPrice = networkFeeForGasLimit
71
+ }
72
+ }
73
+
74
+ let useLimit = 'regularTransaction'
75
+ if (
76
+ spendInfo.currencyCode &&
77
+ spendInfo.currencyCode !== currencyInfo.currencyCode
78
+ ) {
79
+ useLimit = 'tokenTransaction'
80
+ }
81
+
82
+ let networkFeeOption = 'standard'
83
+ if (typeof spendInfo.networkFeeOption === 'string') {
84
+ networkFeeOption = spendInfo.networkFeeOption
85
+ }
86
+
87
+ const gasLimit = networkFeeForGasLimit.gasLimit[useLimit]
88
+ let gasPrice = ''
89
+ if (!spendInfo.spendTargets[0].nativeAmount) {
90
+ throw new Error('ErrorInvalidNativeAmount')
91
+ }
92
+ let nativeAmount = spendInfo.spendTargets[0].nativeAmount
93
+ if (useLimit === 'tokenTransaction') {
94
+ // Small hack. Edgetimate the relative value of token to ethereum as 10%
95
+ nativeAmount = bns.div(nativeAmount, '10')
96
+ }
97
+ if (!networkFeeForGasPrice.gasPrice) {
98
+ throw new Error('ErrorInvalidGasPrice')
99
+ }
100
+ const gasPriceObj = networkFeeForGasPrice.gasPrice
101
+ switch (networkFeeOption) {
102
+ case ES_FEE_LOW:
103
+ gasPrice = gasPriceObj.lowFee
104
+ break
105
+ case ES_FEE_STANDARD: {
106
+ if (
107
+ bns.gte(
108
+ nativeAmount,
109
+ networkFeeForGasPrice.gasPrice.standardFeeHighAmount
110
+ )
111
+ ) {
112
+ gasPrice = gasPriceObj.standardFeeHigh
113
+ break
114
+ }
115
+ if (bns.lte(nativeAmount, gasPriceObj.standardFeeLowAmount)) {
116
+ if (!networkFeeForGasPrice.gasPrice) {
117
+ throw new Error('ErrorInvalidGasPrice')
118
+ }
119
+ gasPrice = networkFeeForGasPrice.gasPrice.standardFeeLow
120
+ break
121
+ }
122
+
123
+ // Scale the fee by the amount the user is sending scaled between standardFeeLowAmount and standardFeeHighAmount
124
+ const lowHighAmountDiff = bns.sub(
125
+ gasPriceObj.standardFeeHighAmount,
126
+ gasPriceObj.standardFeeLowAmount
127
+ )
128
+ const lowHighFeeDiff = bns.sub(
129
+ gasPriceObj.standardFeeHigh,
130
+ gasPriceObj.standardFeeLow
131
+ )
132
+
133
+ // How much above the lowFeeAmount is the user sending
134
+ const amountDiffFromLow = bns.sub(
135
+ nativeAmount,
136
+ gasPriceObj.standardFeeLowAmount
137
+ )
138
+
139
+ // Add this much to the low fee = (amountDiffFromLow * lowHighFeeDiff) / lowHighAmountDiff)
140
+ const temp1 = bns.mul(amountDiffFromLow, lowHighFeeDiff)
141
+ const addFeeToLow = bns.div(temp1, lowHighAmountDiff)
142
+ gasPrice = bns.add(gasPriceObj.standardFeeLow, addFeeToLow)
143
+ break
144
+ }
145
+
146
+ case ES_FEE_HIGH:
147
+ gasPrice = networkFeeForGasPrice.gasPrice.highFee
148
+ break
149
+ default:
150
+ throw new Error(`Invalid networkFeeOption`)
151
+ }
152
+ const out = { gasLimit, gasPrice, useDefaults }
153
+ return out
154
+ } else {
155
+ throw new Error('ErrorInvalidSpendInfo')
156
+ }
157
+ }