@exodus/solana-api 2.5.27 → 2.5.29

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.27",
3
+ "version": "2.5.29",
4
4
  "description": "Exodus internal Solana asset API wrapper",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -23,8 +23,8 @@
23
23
  "@exodus/models": "^10.1.0",
24
24
  "@exodus/nfts-core": "^0.5.0",
25
25
  "@exodus/simple-retry": "^0.0.6",
26
- "@exodus/solana-lib": "^1.7.4",
27
- "@exodus/solana-meta": "^1.0.5",
26
+ "@exodus/solana-lib": "^1.7.5",
27
+ "@exodus/solana-meta": "^1.0.7",
28
28
  "bn.js": "^4.11.0",
29
29
  "debug": "^4.1.1",
30
30
  "lodash": "^4.17.11",
@@ -34,5 +34,5 @@
34
34
  "devDependencies": {
35
35
  "@exodus/assets-testing": "file:../../../__testing__"
36
36
  },
37
- "gitHead": "9e93c3846854f6c64b0bdd5abe103ec5ff980596"
37
+ "gitHead": "7ec211abf9ccbc6b8bc84440f3bc6da659aebaaf"
38
38
  }
package/src/api.js CHANGED
@@ -22,8 +22,9 @@ import { Connection } from './connection'
22
22
 
23
23
  // Doc: https://docs.solana.com/apps/jsonrpc-api
24
24
 
25
- const RPC_URL = 'https://solana.a.exodus.io' // https://vip-api.mainnet-beta.solana.com/, https://api.mainnet-beta.solana.com, https://solana-api.projectserum.com
26
- const WS_ENDPOINT = 'wss://solana.a.exodus.io/ws'
25
+ const RPC_URL = 'https://solana.a.exodus.io' // https://vip-api.mainnet-beta.solana.com/, https://api.mainnet-beta.solana.com
26
+ const WS_ENDPOINT = 'wss://solana.a.exodus.io/ws' // not standard across all node providers (we're compatible only with Quicknode)
27
+ const FORCE_HTTP = true // use https over ws
27
28
 
28
29
  // Tokens + SOL api support
29
30
  export class Api {
@@ -63,6 +64,7 @@ export class Api {
63
64
  handleReconnect,
64
65
  reconnectDelay,
65
66
  }) {
67
+ if (FORCE_HTTP) return false
66
68
  const conn = new Connection({
67
69
  endpoint: this.wsUrl,
68
70
  address,
@@ -89,7 +91,7 @@ export class Api {
89
91
  if (handleTransfers) return handleTransfers(updates)
90
92
  }
91
93
 
92
- async rpcCall(method, params = [], { address = '', forceHttp = false } = {}) {
94
+ async rpcCall(method, params = [], { address = '', forceHttp = FORCE_HTTP } = {}) {
93
95
  // ws request
94
96
  const connection = this.connections[address] || lodash.sample(Object.values(this.connections)) // pick random connection
95
97
  if (lodash.get(connection, 'isOpen') && !lodash.get(connection, 'shutdown') && !forceHttp) {
@@ -119,7 +121,7 @@ export class Api {
119
121
 
120
122
  async getRecentBlockHash(commitment?) {
121
123
  const result = await this.rpcCall(
122
- 'getRecentBlockhash',
124
+ 'getLatestBlockhash',
123
125
  [{ commitment: commitment || 'finalized', encoding: 'jsonParsed' }],
124
126
  { forceHttp: true }
125
127
  )
@@ -340,10 +342,14 @@ export class Api {
340
342
  }, [])
341
343
  .map((ix) => {
342
344
  const type = lodash.get(ix, 'parsed.type')
343
- const isTransferTx = ix.parsed && ix.program === 'spl-token' && type === 'transfer'
345
+ const isTransferTx =
346
+ ix.parsed && ix.program === 'spl-token' && ['transfer', 'transferChecked'].includes(type)
344
347
  const source = lodash.get(ix, 'parsed.info.source')
345
348
  const destination = lodash.get(ix, 'parsed.info.destination')
346
- const amount = Number(lodash.get(ix, 'parsed.info.amount', 0))
349
+ const amount = Number(
350
+ lodash.get(ix, 'parsed.info.amount', 0) ||
351
+ lodash.get(ix, 'parsed.info.tokenAmount.amount', 0)
352
+ )
347
353
 
348
354
  const tokenAccount = tokenAccountsByOwner.find(({ tokenAccountAddress }) => {
349
355
  return [source, destination].includes(tokenAccountAddress)
@@ -798,7 +804,7 @@ export class Api {
798
804
  */
799
805
  broadcastTransaction = async (signedTx, options) => {
800
806
  console.log('Solana broadcasting TX:', signedTx) // base64
801
- const defaultOptions = { encoding: 'base64', preflightCommitment: 'finalized' }
807
+ const defaultOptions = { encoding: 'base64', preflightCommitment: 'confirmed' }
802
808
 
803
809
  const params = [signedTx, { ...defaultOptions, ...options }]
804
810
  const errorMessagesToRetry = ['Blockhash not found']
package/src/index.js CHANGED
@@ -9,6 +9,12 @@ export { default as SolanaFeeMonitor } from './fee-monitor'
9
9
  export { SolanaMonitor } from './tx-log'
10
10
  export { SolanaAccountState } from './account-state'
11
11
  export { getSolStakedFee, getStakingInfo, getUnstakingFee } from './staking-utils'
12
+ export {
13
+ isSolanaStaking,
14
+ isSolanaUnstaking,
15
+ isSolanaWithdrawn,
16
+ isSolanaRewardsActivityTx,
17
+ } from './txs-utils'
12
18
  export { createAndBroadcastTXFactory } from './tx-send'
13
19
  export { getBalancesFactory } from './get-balances'
14
20
 
@@ -0,0 +1,11 @@
1
+ import { get } from 'lodash'
2
+
3
+ const isSolanaTx = (tx) => tx.coinName === 'solana'
4
+ export const isSolanaStaking = (tx) =>
5
+ isSolanaTx(tx) && ['createAccountWithSeed', 'delegate'].includes(get(tx, 'data.staking.method'))
6
+ export const isSolanaUnstaking = (tx) =>
7
+ isSolanaTx(tx) && get(tx, 'data.staking.method') === 'undelegate'
8
+ export const isSolanaWithdrawn = (tx) =>
9
+ isSolanaTx(tx) && get(tx, 'data.staking.method') === 'withdraw'
10
+ export const isSolanaRewardsActivityTx = (tx) =>
11
+ [isSolanaStaking, isSolanaUnstaking, isSolanaWithdrawn].some((fn) => fn(tx))