@exodus/ethereum-api 6.2.32 → 6.3.0
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": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "Ethereum Api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@exodus/models": "^8.10.4"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "c1331451073aaaa3a9faf9f00840cd9b31dfff11"
|
|
38
38
|
}
|
package/src/staking/index.js
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import assert from 'minimalistic-assert'
|
|
2
|
+
import { fetchival } from '@exodus/fetch'
|
|
3
|
+
import ms from 'ms'
|
|
4
|
+
|
|
5
|
+
const DEFAULT_STAKING_URL = 'https://staking.a.exodus.io'
|
|
6
|
+
const HTTP_POST_TIMEOUT = ms('30s')
|
|
7
|
+
|
|
8
|
+
export const stakingProviderClientFactory = (defaultStakingUrl = DEFAULT_STAKING_URL) => {
|
|
9
|
+
assert(defaultStakingUrl, '"defaultStakingUrl" must be provided')
|
|
10
|
+
|
|
11
|
+
let stakingUrl = defaultStakingUrl
|
|
12
|
+
|
|
13
|
+
const assetValidators = {
|
|
14
|
+
polygon: '0xf30cf4ed712d3734161fdaab5b1dbb49fd2d0e5c',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const setStakingUrl = (newStakingUrl) => {
|
|
18
|
+
stakingUrl = newStakingUrl || defaultStakingUrl
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const stakingRequest = ({ asset, data }) => {
|
|
22
|
+
return fetchival(`${stakingUrl}/${asset}/stake`, {
|
|
23
|
+
timeout: HTTP_POST_TIMEOUT,
|
|
24
|
+
}).post(data)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const notifyActionFactory = ({ type }) => {
|
|
28
|
+
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')
|
|
32
|
+
assert(txId, '"txId" is required')
|
|
33
|
+
assert(delegator, '"delegator" is required')
|
|
34
|
+
assert(amount, '"amount" is required')
|
|
35
|
+
|
|
36
|
+
const stakingData = {
|
|
37
|
+
asset,
|
|
38
|
+
data: {
|
|
39
|
+
delegator,
|
|
40
|
+
actions: [
|
|
41
|
+
{
|
|
42
|
+
type,
|
|
43
|
+
validator: assetValidators[asset],
|
|
44
|
+
amount,
|
|
45
|
+
txId,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
return stakingRequest(stakingData)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const notifyStaking = notifyActionFactory({
|
|
55
|
+
type: 'start',
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const notifyUnstaking = notifyActionFactory({
|
|
59
|
+
type: 'stop',
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
return { setStakingUrl, notifyStaking, notifyUnstaking }
|
|
63
|
+
}
|