@exodus/ethereum-api 7.0.0 → 7.0.1
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 +3 -4
- package/src/staking/ethereum/service.js +38 -6
- package/LICENSE.md +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-api",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.1",
|
|
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.
|
|
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,4 +1,5 @@
|
|
|
1
1
|
import { estimateGasLimit, EthereumStaking, getServer } from '@exodus/ethereum-api'
|
|
2
|
+
import { isNumberUnit } from '@exodus/currency'
|
|
2
3
|
import BN from 'bn.js'
|
|
3
4
|
|
|
4
5
|
const extraGasLimit = 20000 // extra gas Limit to prevent tx failing if something change on pool state (till tx is in mempool)
|
|
@@ -10,14 +11,24 @@ export function createEthereumStakingService({
|
|
|
10
11
|
}) {
|
|
11
12
|
const staking = new EthereumStaking(asset)
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
function amountToCurrency({ asset, amount }) {
|
|
15
|
+
return isNumberUnit(amount) ? amount : asset.currency.parse(amount)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function delegate({ walletAccount, amount } = {}) {
|
|
19
|
+
const delegatorAddress = (
|
|
20
|
+
await assetClientInterface.getReceiveAddress({
|
|
21
|
+
assetName: asset.name,
|
|
22
|
+
walletAccount,
|
|
23
|
+
})
|
|
24
|
+
).toLowerCase()
|
|
25
|
+
amount = amountToCurrency({ asset, amount })
|
|
15
26
|
|
|
16
27
|
const { to, data } = await staking.stake({
|
|
17
28
|
amount,
|
|
18
29
|
})
|
|
19
30
|
|
|
20
|
-
const { gasPrice, gasLimit, fee } = await estimateTxFee(
|
|
31
|
+
const { gasPrice, gasLimit, fee } = await estimateTxFee(delegatorAddress, to, amount, data)
|
|
21
32
|
|
|
22
33
|
console.log(
|
|
23
34
|
`delegator address ${delegatorAddress} staking ${amount.toDefaultString({
|
|
@@ -38,12 +49,20 @@ export function createEthereumStakingService({
|
|
|
38
49
|
return txId
|
|
39
50
|
}
|
|
40
51
|
|
|
41
|
-
async function undelegate({ walletAccount,
|
|
52
|
+
async function undelegate({ walletAccount, amount } = {}) {
|
|
42
53
|
/*
|
|
43
54
|
unstakePending balance (not yet in validator) + unstake balance (in validator)
|
|
44
55
|
1. give priority to unstakePending (based on the amount)
|
|
45
56
|
2. unstake amount in validator.
|
|
46
57
|
*/
|
|
58
|
+
amount = amountToCurrency({ asset, amount })
|
|
59
|
+
|
|
60
|
+
const delegatorAddress = (
|
|
61
|
+
await assetClientInterface.getReceiveAddress({
|
|
62
|
+
assetName: asset.name,
|
|
63
|
+
walletAccount,
|
|
64
|
+
})
|
|
65
|
+
).toLowerCase()
|
|
47
66
|
|
|
48
67
|
const pendingAmount = await staking.pendingBalanceOf(delegatorAddress)
|
|
49
68
|
|
|
@@ -109,8 +128,14 @@ export function createEthereumStakingService({
|
|
|
109
128
|
return txId
|
|
110
129
|
}
|
|
111
130
|
|
|
112
|
-
async function claimUndelegatedBalance({ walletAccount
|
|
131
|
+
async function claimUndelegatedBalance({ walletAccount } = {}) {
|
|
113
132
|
// withdraw withdrawable balance (of a previous unstake)
|
|
133
|
+
const delegatorAddress = (
|
|
134
|
+
await assetClientInterface.getReceiveAddress({
|
|
135
|
+
assetName: asset.name,
|
|
136
|
+
walletAccount,
|
|
137
|
+
})
|
|
138
|
+
).toLowerCase()
|
|
114
139
|
|
|
115
140
|
const withdrawRequest = await staking.claimWithdrawRequest({
|
|
116
141
|
address: delegatorAddress,
|
|
@@ -131,7 +156,14 @@ export function createEthereumStakingService({
|
|
|
131
156
|
} else return null // -> no withdrawable balance
|
|
132
157
|
}
|
|
133
158
|
|
|
134
|
-
async function estimateDelegateOperation({
|
|
159
|
+
async function estimateDelegateOperation({ walletAccount, operation, args }) {
|
|
160
|
+
const delegatorAddress = (
|
|
161
|
+
await assetClientInterface.getReceiveAddress({
|
|
162
|
+
assetName: asset.name,
|
|
163
|
+
walletAccount,
|
|
164
|
+
})
|
|
165
|
+
).toLowerCase()
|
|
166
|
+
|
|
135
167
|
const NAMING_MAP = {
|
|
136
168
|
delegate: 'stake',
|
|
137
169
|
undelegate: 'unstake',
|
package/LICENSE.md
DELETED
|
File without changes
|