@exodus/ethereum-api 8.18.2 → 8.18.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/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [8.18.3](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.18.2...@exodus/ethereum-api@8.18.3) (2024-09-17)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **staking:** ETH unstake event ([#3552](https://github.com/ExodusMovement/assets/issues/3552)) ([116fa18](https://github.com/ExodusMovement/assets/commit/116fa18dd2d29e549e0aae30e8e849203f013a75))
12
+
13
+
14
+
6
15
  ## [8.18.2](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.18.1...@exodus/ethereum-api@8.18.2) (2024-09-17)
7
16
 
8
17
  **Note:** Version bump only for package @exodus/ethereum-api
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "8.18.2",
3
+ "version": "8.18.3",
4
4
  "description": "Ethereum Api",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -65,5 +65,5 @@
65
65
  "type": "git",
66
66
  "url": "git+https://github.com/ExodusMovement/assets.git"
67
67
  },
68
- "gitHead": "ddeb04e25e5cb7dda81cc453c292e3aa6bfa25a1"
68
+ "gitHead": "a5069848e89037f899ba2a96c3661ccbd2b66290"
69
69
  }
@@ -83,14 +83,7 @@ export function createEthereumStakingService({
83
83
  amount: inactiveAmountToUnstake,
84
84
  })
85
85
 
86
- let feeData
87
- try {
88
- // could revert and break the whole fee calculation
89
- feeData = await estimateTxFee(delegatorAddress, to, null, data)
90
- } catch {
91
- console.warn('ETH unstake pending estimation reverted')
92
- return Object.create(null)
93
- }
86
+ const feeData = await estimateTxFee(delegatorAddress, to, null, data)
94
87
 
95
88
  return { to, txData: data, ...feeData }
96
89
  }
@@ -98,7 +91,10 @@ export function createEthereumStakingService({
98
91
  async function getUndelegateData({ delegatorAddress, resquestedAmount, pendingAmount }) {
99
92
  const canUnstake = resquestedAmount.gt(pendingAmount)
100
93
 
101
- if (!canUnstake) return Object.create(null)
94
+ if (!canUnstake) {
95
+ console.warn('UnstakePending covered requested unstake. Nothing to unstake from validator')
96
+ return Object.create(null)
97
+ }
102
98
 
103
99
  const activeAmountToUnstake = resquestedAmount.sub(pendingAmount)
104
100
  const { to, data } = await staking.unstake({
@@ -124,12 +120,24 @@ export function createEthereumStakingService({
124
120
  const delegatorAddress = address.toLowerCase()
125
121
  const pendingAmount = await staking.pendingBalanceOf(delegatorAddress)
126
122
 
127
- const { fee: undelegatePendingFee = asset.currency.ZERO } = await getUndelegatePendingData({
128
- delegatorAddress,
129
- resquestedAmount,
130
- pendingAmount,
131
- minAmount,
132
- })
123
+ let undelegatePendingFee = asset.currency.ZERO
124
+
125
+ if (pendingAmount.isPositive) {
126
+ try {
127
+ // try to estimate unstakePending
128
+ const { fee } = await getUndelegatePendingData({
129
+ delegatorAddress,
130
+ resquestedAmount,
131
+ pendingAmount,
132
+ minAmount,
133
+ })
134
+ undelegatePendingFee = fee
135
+ } catch (err) {
136
+ // useful to debug fee calculation
137
+ console.warn('ETH unstake pending estimation failed, continuing with unstake', err)
138
+ }
139
+ }
140
+
133
141
  const { fee: undelegateFee = asset.currency.ZERO } = await getUndelegateData({
134
142
  delegatorAddress,
135
143
  resquestedAmount,
@@ -173,6 +181,7 @@ export function createEthereumStakingService({
173
181
  txId = await prepareAndSendTx({
174
182
  asset,
175
183
  walletAccount,
184
+ waitForConfirmation: true, // wait for tx confirmation in the client
176
185
  ...undelegatePendingData,
177
186
  })
178
187
  }
@@ -184,16 +193,16 @@ export function createEthereumStakingService({
184
193
  pendingAmount,
185
194
  })
186
195
 
187
- if (!undelegateData) return txId
188
-
189
- txId = await prepareAndSendTx({
190
- asset,
191
- walletAccount,
192
- ...undelegateData,
193
- })
196
+ if (undelegateData.fee) {
197
+ txId = await prepareAndSendTx({
198
+ asset,
199
+ walletAccount,
200
+ ...undelegateData,
201
+ })
202
+ }
194
203
 
195
204
  // Testnet assets do not support delegations tracking
196
- if (asset.name === 'ethereum')
205
+ if (txId && asset.name === 'ethereum')
197
206
  await stakingProvider.notifyUnstaking({
198
207
  txId,
199
208
  asset: asset.name,
@@ -297,9 +306,17 @@ export function createEthereumStakingService({
297
306
  }
298
307
 
299
308
  async function prepareAndSendTx(
300
- { asset, walletAccount, to, amount, txData: txInput, gasPrice, gasLimit, fee } = Object.create(
301
- null
302
- )
309
+ {
310
+ asset,
311
+ walletAccount,
312
+ to,
313
+ amount,
314
+ txData: txInput,
315
+ gasPrice,
316
+ gasLimit,
317
+ fee,
318
+ waitForConfirmation = false,
319
+ } = Object.create(null)
303
320
  ) {
304
321
  const sendTxArgs = {
305
322
  asset,
@@ -322,6 +339,7 @@ export function createEthereumStakingService({
322
339
  gasLimit,
323
340
  feeAmount: fee,
324
341
  },
342
+ waitForConfirmation,
325
343
  }
326
344
 
327
345
  console.log('sending staking tx:', sendTxArgs)