@exodus/solana-api 2.5.9 → 2.5.11

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": "2.5.9",
3
+ "version": "2.5.11",
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.4",
26
+ "@exodus/solana-lib": "^1.6.5",
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": "123d67b94e313496373a6ec97447361bb6bec6d7"
34
+ "gitHead": "44fca2a6ee944fb8e96c0a8918845b1dc7cc5242"
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
- // eslint-disable-next-line
45
- const obj = url.parse(reqUrl)
43
+ const obj = new URL(reqUrl)
46
44
  obj.protocol = 'wss:'
47
- reqUrl = url.format(obj)
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
 
@@ -216,9 +225,11 @@ export class SolanaMonitor extends BaseMonitor {
216
225
  return this.updateAccountState({ newData, walletAccount })
217
226
  }
218
227
 
219
- async updateStakingInfo({ walletAccount, address }) {
228
+ async updateStakingInfo({ walletAccount, address, stakingAddresses = [] }) {
220
229
  const stakingInfo = await this.api.getStakeAccountsInfo(address)
221
- const rewards = await this.api.getRewards(Object.keys(stakingInfo.accounts))
230
+ // merge current and old staking addresses
231
+ const allStakingAddresses = _.uniq([...Object.keys(stakingInfo.accounts), ...stakingAddresses])
232
+ const rewards = await this.api.getRewards(allStakingAddresses)
222
233
  const mem = {
223
234
  loaded: true,
224
235
  staking: this.staking,