@exodus/solana-api 3.5.0 → 3.6.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/solana-api",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "Exodus internal Solana asset API wrapper",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -45,5 +45,5 @@
45
45
  "@exodus/assets-testing": "^1.0.0",
46
46
  "@solana/web3.js": "^1.91.8"
47
47
  },
48
- "gitHead": "df4517e2015f23287167aaa7ff5a3bc037851294"
48
+ "gitHead": "4150f6ca3557ebe8bb5bed70bc1934cc2bd97716"
49
49
  }
package/src/index.js CHANGED
@@ -16,6 +16,7 @@ export {
16
16
  } from './txs-utils'
17
17
  export { createAndBroadcastTXFactory } from './tx-send'
18
18
  export { getBalancesFactory } from './get-balances'
19
+ export { stakingProviderClientFactory } from './staking-provider-client'
19
20
 
20
21
  // These are not the same asset objects as the wallet creates, so they should never be returned to the wallet.
21
22
  // Initially this may be violated by the Solana code until the first monitor tick updates assets with setTokens()
@@ -0,0 +1,66 @@
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
+ const SOLANA_VALIDATOR = '9QU2QSxhb24FUX3Tu2FpczXjpK3VYrvRudywSZaM29mF' // Everstake
9
+
10
+ export const stakingProviderClientFactory = (
11
+ { defaultStakingUrl = DEFAULT_STAKING_URL } = Object.create(null)
12
+ ) => {
13
+ assert(defaultStakingUrl, 'defaultStakingUrl must be provided')
14
+ let stakingUrl = defaultStakingUrl
15
+
16
+ const setStakingUrl = (newStakingUrl) => {
17
+ stakingUrl = new URL(newStakingUrl || defaultStakingUrl)
18
+ }
19
+
20
+ const stakingRequest = ({ asset: assetName, data }) => {
21
+ return fetchival(stakingUrl, {
22
+ timeout: HTTP_POST_TIMEOUT,
23
+ })(assetName)('stake').post(data)
24
+ }
25
+
26
+ const notifyActionFactory = ({ type }) => {
27
+ assert(type, '"type" is required')
28
+ return async ({ asset: assetName, txId, delegator, amount, error }) => {
29
+ assert(assetName, '"asset" must be provided')
30
+ assert(SOLANA_VALIDATOR, '"invalid" validator')
31
+ assert(txId, '"txId" is required')
32
+ assert(delegator, '"delegator" is required')
33
+ assert(amount, '"amount" is required')
34
+
35
+ const stakingData = {
36
+ asset: assetName,
37
+ data: {
38
+ delegator,
39
+ actions: [
40
+ {
41
+ type,
42
+ validator: SOLANA_VALIDATOR,
43
+ amount,
44
+ txId,
45
+ },
46
+ ],
47
+ },
48
+ }
49
+ return stakingRequest(stakingData)
50
+ }
51
+ }
52
+
53
+ const notifyStaking = notifyActionFactory({
54
+ type: 'start',
55
+ })
56
+
57
+ const notifyWithdraw = notifyActionFactory({
58
+ type: 'stop',
59
+ })
60
+
61
+ return {
62
+ setStakingUrl,
63
+ notifyStaking,
64
+ notifyWithdraw,
65
+ }
66
+ }