@exodus/ethereum-api 7.0.0 → 7.0.2

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": "7.0.0",
3
+ "version": "7.0.2",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -29,7 +29,7 @@
29
29
  "make-concurrent": "4.0.0",
30
30
  "minimalistic-assert": "^1.0.1",
31
31
  "ms": "^2.1.1",
32
- "socket.io-client": "2.5.0",
32
+ "socket.io-client": "2.1.1",
33
33
  "ws": "^6.1.0"
34
34
  },
35
35
  "devDependencies": {
@@ -37,6 +37,5 @@
37
37
  "@exodus/assets-base": "^8.1.14",
38
38
  "@exodus/assets-testing": "file:../../../__testing__",
39
39
  "@exodus/models": "^11.0.0"
40
- },
41
- "gitHead": "1ebfe4c6b2ba3cc49564290a498571e5f3921a5d"
40
+ }
42
41
  }
@@ -1,5 +1,7 @@
1
1
  import { estimateGasLimit, EthereumStaking, getServer } from '@exodus/ethereum-api'
2
+ import { isNumberUnit } from '@exodus/currency'
2
3
  import BN from 'bn.js'
4
+ import { stakingProviderClientFactory } from '../staking-provider-client'
3
5
 
4
6
  const extraGasLimit = 20000 // extra gas Limit to prevent tx failing if something change on pool state (till tx is in mempool)
5
7
 
@@ -9,15 +11,26 @@ export function createEthereumStakingService({
9
11
  createAndBroadcastTX,
10
12
  }) {
11
13
  const staking = new EthereumStaking(asset)
14
+ const stakingProvider = stakingProviderClientFactory()
12
15
 
13
- async function delegate({ walletAccount, delegatorAddress, amount } = {}) {
14
- const _delegatorAddress = delegatorAddress.toLowerCase()
16
+ function amountToCurrency({ asset, amount }) {
17
+ return isNumberUnit(amount) ? amount : asset.currency.parse(amount)
18
+ }
19
+
20
+ async function delegate({ walletAccount, amount } = {}) {
21
+ const delegatorAddress = (
22
+ await assetClientInterface.getReceiveAddress({
23
+ assetName: asset.name,
24
+ walletAccount,
25
+ })
26
+ ).toLowerCase()
27
+ amount = amountToCurrency({ asset, amount })
15
28
 
16
29
  const { to, data } = await staking.stake({
17
30
  amount,
18
31
  })
19
32
 
20
- const { gasPrice, gasLimit, fee } = await estimateTxFee(_delegatorAddress, to, amount, data)
33
+ const { gasPrice, gasLimit, fee } = await estimateTxFee(delegatorAddress, to, amount, data)
21
34
 
22
35
  console.log(
23
36
  `delegator address ${delegatorAddress} staking ${amount.toDefaultString({
@@ -35,15 +48,32 @@ export function createEthereumStakingService({
35
48
  fee,
36
49
  })
37
50
 
51
+ // Goerli is not supported
52
+ if (asset.name === 'ethereum')
53
+ await stakingProvider.notifyStaking({
54
+ txId,
55
+ asset: asset.name,
56
+ delegator: delegatorAddress,
57
+ amount: amount.toBaseString(),
58
+ })
59
+
38
60
  return txId
39
61
  }
40
62
 
41
- async function undelegate({ walletAccount, delegatorAddress, amount } = {}) {
63
+ async function undelegate({ walletAccount, amount } = {}) {
42
64
  /*
43
65
  unstakePending balance (not yet in validator) + unstake balance (in validator)
44
66
  1. give priority to unstakePending (based on the amount)
45
67
  2. unstake amount in validator.
46
68
  */
69
+ amount = amountToCurrency({ asset, amount })
70
+
71
+ const delegatorAddress = (
72
+ await assetClientInterface.getReceiveAddress({
73
+ assetName: asset.name,
74
+ walletAccount,
75
+ })
76
+ ).toLowerCase()
47
77
 
48
78
  const pendingAmount = await staking.pendingBalanceOf(delegatorAddress)
49
79
 
@@ -106,11 +136,26 @@ export function createEthereumStakingService({
106
136
  })
107
137
  }
108
138
 
139
+ // Goerli is not supported
140
+ if (asset.name === 'ethereum')
141
+ await stakingProvider.notifyUnstaking({
142
+ txId,
143
+ asset: asset.name,
144
+ delegator: delegatorAddress,
145
+ amount: amount.toBaseString(),
146
+ })
147
+
109
148
  return txId
110
149
  }
111
150
 
112
- async function claimUndelegatedBalance({ walletAccount, delegatorAddress } = {}) {
151
+ async function claimUndelegatedBalance({ walletAccount } = {}) {
113
152
  // withdraw withdrawable balance (of a previous unstake)
153
+ const delegatorAddress = (
154
+ await assetClientInterface.getReceiveAddress({
155
+ assetName: asset.name,
156
+ walletAccount,
157
+ })
158
+ ).toLowerCase()
114
159
 
115
160
  const withdrawRequest = await staking.claimWithdrawRequest({
116
161
  address: delegatorAddress,
@@ -131,7 +176,14 @@ export function createEthereumStakingService({
131
176
  } else return null // -> no withdrawable balance
132
177
  }
133
178
 
134
- async function estimateDelegateOperation({ delegatorAddress, operation, args }) {
179
+ async function estimateDelegateOperation({ walletAccount, operation, args }) {
180
+ const delegatorAddress = (
181
+ await assetClientInterface.getReceiveAddress({
182
+ assetName: asset.name,
183
+ walletAccount,
184
+ })
185
+ ).toLowerCase()
186
+
135
187
  const NAMING_MAP = {
136
188
  delegate: 'stake',
137
189
  undelegate: 'unstake',
@@ -143,6 +195,8 @@ export function createEthereumStakingService({
143
195
  return
144
196
  }
145
197
 
198
+ if (args.amount) args.amount = amountToCurrency({ asset, amount: args.amount })
199
+
146
200
  let amount, data, fee
147
201
  try {
148
202
  ;({ amount, data } = await delegateOperation(args))
package/LICENSE.md DELETED
File without changes