@exodus/solana-api 3.4.2 → 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 +4 -3
- package/src/api.js +9 -0
- package/src/index.js +1 -0
- package/src/staking-provider-client.js +66 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-api",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Exodus internal Solana asset API wrapper",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"wretch": "^1.5.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@exodus/assets-testing": "^1.0.0"
|
|
45
|
+
"@exodus/assets-testing": "^1.0.0",
|
|
46
|
+
"@solana/web3.js": "^1.91.8"
|
|
46
47
|
},
|
|
47
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "4150f6ca3557ebe8bb5bed70bc1934cc2bd97716"
|
|
48
49
|
}
|
package/src/api.js
CHANGED
|
@@ -893,6 +893,15 @@ export class Api {
|
|
|
893
893
|
return response && response.value ? response.value : []
|
|
894
894
|
}
|
|
895
895
|
|
|
896
|
+
async getFeeForMessage(message, commitment) {
|
|
897
|
+
const response = await this.rpcCall('getFeeForMessage', [
|
|
898
|
+
Buffer.from(message.serialize()).toString('base64'),
|
|
899
|
+
{ commitment },
|
|
900
|
+
])
|
|
901
|
+
|
|
902
|
+
return lodash.get(response, 'value')
|
|
903
|
+
}
|
|
904
|
+
|
|
896
905
|
/**
|
|
897
906
|
* Broadcast a signed transaction
|
|
898
907
|
*/
|
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
|
+
}
|