@exodus/ethereum-api 6.3.27 → 6.3.29

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/LICENSE.md ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "6.3.27",
3
+ "version": "6.3.29",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "@exodus/asset-lib": "^3.7.1",
18
18
  "@exodus/crypto": "^1.0.0-rc.0",
19
- "@exodus/ethereum-lib": "^3.3.41",
19
+ "@exodus/ethereum-lib": "^3.3.42",
20
20
  "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
21
21
  "@exodus/fetch": "^1.3.0-beta.4",
22
22
  "@exodus/simple-retry": "^0.0.6",
@@ -33,5 +33,6 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@exodus/models": "^8.10.4"
36
- }
36
+ },
37
+ "gitHead": "01457e8fa6da6b468680885d4e086699842e2ee0"
37
38
  }
@@ -142,9 +142,10 @@ export class EthereumStaking {
142
142
  }
143
143
  }
144
144
 
145
+ /* Unstake funds that are staked into the validator. Once unstaked they need to be claimed (once ready to withdraw) */
145
146
  async unstake({ address, amount, allowedInterchangeNum = 0, source = '2' }) {
146
147
  const amountWei = amount.toBaseString()
147
- const balance = await this.autocompoundBalanceOf(address)
148
+ const balance = await this.autocompoundBalanceOf(address) // amount staked into the validator (active balance)
148
149
 
149
150
  if (balance.gte(amount)) {
150
151
  return {
@@ -1,7 +1,7 @@
1
1
  import { estimateGasLimit, EthereumStaking, getServer } from '@exodus/ethereum-api'
2
2
  import BN from 'bn.js'
3
3
 
4
- const delegateGas = 500000 // approx gas limits
4
+ const extraGasLimit = 150000 // extra gas Limit to prevent tx failing if something change on pool state (till tx is in mempool)
5
5
 
6
6
  export function createEthereumStakingService({
7
7
  asset,
@@ -143,30 +143,25 @@ export function createEthereumStakingService({
143
143
  return
144
144
  }
145
145
 
146
- const { amount, data } = await delegateOperation(args)
147
- const { fee } = await estimateTxFee(delegatorAddress, staking.poolAddress, amount, data)
146
+ let amount, data, fee
147
+ try {
148
+ ;({ amount, data } = await delegateOperation(args))
149
+ ;({ fee } = await estimateTxFee(delegatorAddress, staking.poolAddress, amount, data))
150
+ } catch (e) {
151
+ // If the operation is to unstake and failed retry with unstakePending
152
+ if (operation === 'undelegate') {
153
+ ;({ amount, data } = await staking.unstakePending(args))
154
+ ;({ fee } = await estimateTxFee(delegatorAddress, staking.poolAddress, amount, data))
155
+ } else {
156
+ throw e
157
+ }
158
+ }
148
159
 
149
160
  return fee
150
161
  }
151
162
 
152
- async function estimateUndelegateTxFee() {
153
- const gasPrice = parseInt(await getServer(asset).gasPrice(), 16)
154
-
155
- const gasLimit = delegateGas
156
- const fee = new BN(gasLimit).mul(new BN(gasPrice))
157
- return {
158
- gasLimit,
159
- gasPrice: asset.currency.baseUnit(gasPrice),
160
- fee: asset.currency.baseUnit(fee.toString()),
161
- }
162
- }
163
-
164
163
  async function estimateTxFee(from, to, amount, txInput, gasPrice = '0x0') {
165
164
  amount = amount || asset.currency.ZERO
166
- if (amount.isZero) {
167
- // unstaking txs
168
- return estimateUndelegateTxFee() // otherwise server estimateGasLimit will throw "execution reverted"
169
- }
170
165
 
171
166
  const gasLimit = await estimateGasLimit(
172
167
  asset,
@@ -182,7 +177,7 @@ export function createEthereumStakingService({
182
177
  }
183
178
 
184
179
  gasPrice = parseInt(gasPrice, 16)
185
- const fee = new BN(gasPrice).mul(new BN(gasLimit))
180
+ const fee = new BN(gasPrice).mul(new BN(gasLimit + extraGasLimit))
186
181
 
187
182
  return {
188
183
  gasLimit,
@@ -12,6 +12,7 @@ export const stakingProviderClientFactory = (defaultStakingUrl = DEFAULT_STAKING
12
12
 
13
13
  const assetValidators = {
14
14
  polygon: '0x3f4ce357b9d61d3b904492b8b5abc69c6c693720',
15
+ ethereum: '0xd523794c879d9ec028960a231f866758e405be34',
15
16
  }
16
17
 
17
18
  const setStakingUrl = (newStakingUrl) => {
@@ -26,21 +27,21 @@ export const stakingProviderClientFactory = (defaultStakingUrl = DEFAULT_STAKING
26
27
 
27
28
  const notifyActionFactory = ({ type }) => {
28
29
  assert(type, '"type" is required')
29
- return async ({ asset, txId, delegator, amount, error }) => {
30
- assert(asset, '"asset" must be provided')
31
- assert(assetValidators[asset], '"invalid" asset')
30
+ return async ({ asset: assetName, txId, delegator, amount, error }) => {
31
+ assert(assetName, '"asset" must be provided')
32
+ assert(assetValidators[assetName], '"invalid" asset')
32
33
  assert(txId, '"txId" is required')
33
34
  assert(delegator, '"delegator" is required')
34
35
  assert(amount, '"amount" is required')
35
36
 
36
37
  const stakingData = {
37
- asset,
38
+ asset: assetName,
38
39
  data: {
39
40
  delegator,
40
41
  actions: [
41
42
  {
42
43
  type,
43
- validator: assetValidators[asset],
44
+ validator: assetValidators[assetName],
44
45
  amount,
45
46
  txId,
46
47
  },