@exodus/solana-api 2.5.8 → 2.5.10
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 -3
- package/src/connection.js +2 -4
- package/src/tx-log/solana-monitor.js +19 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-api",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.10",
|
|
4
4
|
"description": "Exodus internal Solana asset API wrapper",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@exodus/models": "^8.10.4",
|
|
24
24
|
"@exodus/nfts-core": "^0.5.0",
|
|
25
25
|
"@exodus/simple-retry": "^0.0.6",
|
|
26
|
-
"@exodus/solana-lib": "^1.6.
|
|
26
|
+
"@exodus/solana-lib": "^1.6.4",
|
|
27
27
|
"@exodus/solana-meta": "^1.0.2",
|
|
28
28
|
"bn.js": "^4.11.0",
|
|
29
29
|
"debug": "^4.1.1",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"url-join": "4.0.0",
|
|
32
32
|
"wretch": "^1.5.2"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "eee9405e4872054f731aafc9723c26209a4b1a31"
|
|
35
35
|
}
|
package/src/connection.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import ms from 'ms'
|
|
2
2
|
import delay from 'delay'
|
|
3
|
-
import url from 'url'
|
|
4
3
|
import lodash from 'lodash'
|
|
5
4
|
import debugLogger from 'debug'
|
|
6
5
|
import { WebSocket } from '@exodus/fetch'
|
|
@@ -41,10 +40,9 @@ export class Connection {
|
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
newSocket(reqUrl) {
|
|
44
|
-
|
|
45
|
-
const obj = url.parse(reqUrl)
|
|
43
|
+
const obj = new URL(reqUrl)
|
|
46
44
|
obj.protocol = 'wss:'
|
|
47
|
-
reqUrl =
|
|
45
|
+
reqUrl = `${obj}`
|
|
48
46
|
debug('Opening WS to:', reqUrl)
|
|
49
47
|
const ws = new WebSocket(`${reqUrl}`)
|
|
50
48
|
ws.onmessage = this.onMessage.bind(this)
|
|
@@ -75,6 +75,14 @@ export class SolanaMonitor extends BaseMonitor {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
async getStakingAddressesFromTxLog({ assetName, walletAccount }) {
|
|
79
|
+
const txLog = await this.aci.getTxLog({ assetName: this.asset.name, walletAccount })
|
|
80
|
+
const stakingAddresses = Array.from(txLog)
|
|
81
|
+
.filter((tx) => _.get(tx, 'data.staking.stakeAddresses'))
|
|
82
|
+
.map((tx) => tx.data.staking.stakeAddresses)
|
|
83
|
+
return _.uniq(_.flatten(stakingAddresses))
|
|
84
|
+
}
|
|
85
|
+
|
|
78
86
|
async tick({ walletAccount, refresh }) {
|
|
79
87
|
// Check for new wallet account
|
|
80
88
|
await this.initWalletAccount({ walletAccount })
|
|
@@ -85,6 +93,7 @@ export class SolanaMonitor extends BaseMonitor {
|
|
|
85
93
|
|
|
86
94
|
const accountState = await this.aci.getAccountState({ assetName, walletAccount })
|
|
87
95
|
const address = await this.aci.getReceiveAddress({ assetName, walletAccount })
|
|
96
|
+
const stakingAddresses = await this.getStakingAddressesFromTxLog({ assetName, walletAccount })
|
|
88
97
|
|
|
89
98
|
const { logItemsByAsset, hasNewTxs, cursorState } = await this.getHistory({
|
|
90
99
|
address,
|
|
@@ -97,7 +106,7 @@ export class SolanaMonitor extends BaseMonitor {
|
|
|
97
106
|
|
|
98
107
|
const cursorChanged = this.hasNewCursor({ walletAccount, cursorState })
|
|
99
108
|
if (refresh || cursorChanged) {
|
|
100
|
-
staking = await this.updateStakingInfo({ walletAccount, address })
|
|
109
|
+
staking = await this.updateStakingInfo({ walletAccount, address, stakingAddresses })
|
|
101
110
|
this.cursors[walletAccount] = cursorState.cursor
|
|
102
111
|
}
|
|
103
112
|
|
|
@@ -146,6 +155,7 @@ export class SolanaMonitor extends BaseMonitor {
|
|
|
146
155
|
// send transaction
|
|
147
156
|
item.to = tx.to
|
|
148
157
|
item.feeAmount = baseAsset.currency.baseUnit(tx.fee).toDefault() // in SOL
|
|
158
|
+
item.feeCointName = baseAsset.name
|
|
149
159
|
item.coinAmount = item.coinAmount.negate()
|
|
150
160
|
|
|
151
161
|
if (tx.to === tx.owner) {
|
|
@@ -153,7 +163,10 @@ export class SolanaMonitor extends BaseMonitor {
|
|
|
153
163
|
item.coinAmount = asset.currency.ZERO
|
|
154
164
|
}
|
|
155
165
|
} else if (tx.unparsed) {
|
|
156
|
-
if (tx.fee !== 0)
|
|
166
|
+
if (tx.fee !== 0) {
|
|
167
|
+
item.feeAmount = baseAsset.currency.baseUnit(tx.fee).toDefault() // in SOL
|
|
168
|
+
item.feeCointName = baseAsset.name
|
|
169
|
+
}
|
|
157
170
|
|
|
158
171
|
item.data.meta = tx.data.meta
|
|
159
172
|
}
|
|
@@ -212,9 +225,11 @@ export class SolanaMonitor extends BaseMonitor {
|
|
|
212
225
|
return this.updateAccountState({ newData, walletAccount })
|
|
213
226
|
}
|
|
214
227
|
|
|
215
|
-
async updateStakingInfo({ walletAccount, address }) {
|
|
228
|
+
async updateStakingInfo({ walletAccount, address, stakingAddresses = [] }) {
|
|
216
229
|
const stakingInfo = await this.api.getStakeAccountsInfo(address)
|
|
217
|
-
|
|
230
|
+
// merge current and old staking addresses
|
|
231
|
+
const allStakingAddresses = _.uniq([...Object.keys(stakingInfo.accounts), ...stakingAddresses])
|
|
232
|
+
const rewards = await this.api.getRewards(allStakingAddresses)
|
|
218
233
|
const mem = {
|
|
219
234
|
loaded: true,
|
|
220
235
|
staking: this.staking,
|