@exodus/solana-api 3.10.0 → 3.11.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/CHANGELOG.md CHANGED
@@ -3,6 +3,31 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.11.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.10.1...@exodus/solana-api@3.11.0) (2024-09-11)
7
+
8
+
9
+ ### Features
10
+
11
+ * switch solana to ESM ([#3412](https://github.com/ExodusMovement/assets/issues/3412)) ([c1d30ce](https://github.com/ExodusMovement/assets/commit/c1d30ce752c9d2aa0667f98a8b90a55396fec286))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * exodus/asset-json-rpc is cjs exporting an object with 'default' ([#3312](https://github.com/ExodusMovement/assets/issues/3312)) ([d6fee86](https://github.com/ExodusMovement/assets/commit/d6fee8693517859fc445c062c0cf97c618da0fad))
17
+ * solana socket id collisions ([#3422](https://github.com/ExodusMovement/assets/issues/3422)) ([d6df7d5](https://github.com/ExodusMovement/assets/commit/d6df7d5ca08dd707dc52d8726802d5fc9bbd17a2))
18
+ * **solana-api:** websocket fixes and performance ([#3419](https://github.com/ExodusMovement/assets/issues/3419)) ([664dacd](https://github.com/ExodusMovement/assets/commit/664dacdcefe68e84ae10b9beeffea8b1af6074a0))
19
+
20
+
21
+
22
+ ## [3.10.1](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.10.0...@exodus/solana-api@3.10.1) (2024-08-26)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * update exodus/timer ([#3134](https://github.com/ExodusMovement/assets/issues/3134)) ([e977be5](https://github.com/ExodusMovement/assets/commit/e977be5280c214c1b814409d9461ce6628bb19be))
28
+
29
+
30
+
6
31
  ## [3.10.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.9.4...@exodus/solana-api@3.10.0) (2024-08-08)
7
32
 
8
33
 
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@exodus/solana-api",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "description": "Exodus internal Solana asset API wrapper",
5
+ "type": "module",
5
6
  "main": "src/index.js",
6
7
  "files": [
7
8
  "src",
@@ -16,23 +17,22 @@
16
17
  "access": "restricted"
17
18
  },
18
19
  "scripts": {
19
- "test": "run -T exodus-test --jest --esbuild",
20
- "lint": "run -T eslint .",
20
+ "test": "run -T exodus-test --jest",
21
+ "lint": "run -T eslintc .",
21
22
  "lint:fix": "yarn lint --fix"
22
23
  },
23
24
  "dependencies": {
24
25
  "@exodus/asset-json-rpc": "^1.0.0",
25
- "@exodus/asset-lib": "^4.1.0",
26
- "@exodus/assets": "^9.0.1",
27
- "@exodus/basic-utils": "^2.1.0",
28
- "@exodus/currency": "^2.3.2",
26
+ "@exodus/asset-lib": "^5.0.0",
27
+ "@exodus/assets": "^11.0.0",
28
+ "@exodus/basic-utils": "^3.0.1",
29
+ "@exodus/currency": "^5.0.2",
29
30
  "@exodus/fetch": "^1.2.0",
30
- "@exodus/models": "^10.1.0",
31
- "@exodus/nfts-core": "^0.5.0",
31
+ "@exodus/models": "^12.0.1",
32
32
  "@exodus/simple-retry": "^0.0.6",
33
- "@exodus/solana-lib": "^3.4.2",
34
- "@exodus/solana-meta": "^1.0.7",
35
- "@exodus/timer": "^1.0.0",
33
+ "@exodus/solana-lib": "^3.6.0",
34
+ "@exodus/solana-meta": "^2.0.0",
35
+ "@exodus/timer": "^1.1.1",
36
36
  "bn.js": "^4.11.0",
37
37
  "debug": "^4.1.1",
38
38
  "delay": "^4.0.1",
@@ -45,9 +45,9 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@exodus/assets-testing": "^1.0.0",
48
- "@solana/web3.js": "^1.91.8"
48
+ "@exodus/solana-web3.js": "^1.63.1-exodus.9-rc2"
49
49
  },
50
- "gitHead": "101deb0e348677bb19d301df54c53557a64f80fe",
50
+ "gitHead": "b41d4471ed86010b8eed3e22af9503f01e5ff595",
51
51
  "bugs": {
52
52
  "url": "https://github.com/ExodusMovement/assets/issues?q=is%3Aissue+is%3Aopen+label%3Asolana-api"
53
53
  },
@@ -1,7 +1,9 @@
1
1
  import { assetsListToObject } from '@exodus/assets'
2
2
  import { isNumberUnit } from '@exodus/currency'
3
3
  import { AccountState } from '@exodus/models'
4
- import { isString, reduce } from 'lodash'
4
+ import lodash from 'lodash'
5
+
6
+ const { isString, reduce } = lodash
5
7
 
6
8
  const parseBalance = (balance, asset) =>
7
9
  !isNumberUnit(balance) && isString(balance) ? asset.currency.parse(balance) : balance
package/src/api.js CHANGED
@@ -1,5 +1,4 @@
1
- import createApi from '@exodus/asset-json-rpc'
2
- import { magicEden } from '@exodus/nfts-core'
1
+ import createApiCJS from '@exodus/asset-json-rpc'
3
2
  import { retry } from '@exodus/simple-retry'
4
3
  import {
5
4
  buildRawTransaction,
@@ -14,13 +13,15 @@ import {
14
13
  TOKEN_2022_PROGRAM_ID,
15
14
  TOKEN_PROGRAM_ID,
16
15
  } from '@exodus/solana-lib'
17
- import assert from 'assert'
18
16
  import BN from 'bn.js'
19
17
  import lodash from 'lodash'
18
+ import assert from 'minimalistic-assert'
20
19
  import urljoin from 'url-join'
21
20
  import wretch from 'wretch'
22
21
 
23
- import { Connection } from './connection'
22
+ import { Connection } from './connection.js'
23
+
24
+ const createApi = createApiCJS.default || createApiCJS
24
25
 
25
26
  // Doc: https://docs.solana.com/apps/jsonrpc-api
26
27
 
@@ -491,7 +492,7 @@ export class Api {
491
492
  }
492
493
  } else {
493
494
  // Token tx
494
- assert.ok(
495
+ assert(
495
496
  Array.isArray(tokenAccountsByOwner),
496
497
  'tokenAccountsByOwner is required when parsing token tx'
497
498
  )
@@ -988,32 +989,14 @@ export class Api {
988
989
  ])
989
990
 
990
991
  const tokenMetaPlex = _tokenMetaPlex || { name: null, symbol: null }
991
- let nft = {
992
- collectionId: null,
993
- collectionName: null,
994
- collectionTitle: null,
995
- title: null,
996
- }
992
+ let nft = Object.create(null)
997
993
 
998
994
  // Only perform an NFT check (getSupply) if decimal is zero
999
995
  if (decimal === 0 && (await _getSupply(account.mint)) === '1') {
1000
- try {
1001
- const {
1002
- id: collectionId,
1003
- collectionName,
1004
- collectionTitle,
1005
- title,
1006
- } = await magicEden.api.getNFTByMintAddress(account.mint)
1007
- nft = {
1008
- collectionId,
1009
- collectionTitle,
1010
- collectionName,
1011
- title,
1012
- }
1013
- tokenMetaPlex.name = tokenMetaPlex.name || collectionTitle
1014
- tokenMetaPlex.symbol = tokenMetaPlex.symbol || collectionName
1015
- } catch (error) {
1016
- console.warn(error)
996
+ const compositeId = account.mint
997
+ nft = {
998
+ id: `solana:${compositeId}`,
999
+ compositeId,
1017
1000
  }
1018
1001
  }
1019
1002
 
package/src/connection.js CHANGED
@@ -40,12 +40,13 @@ export class Connection {
40
40
  this.pingTimeout = null
41
41
  this.reconnectTimeout = null
42
42
  this.txCache = {}
43
+ this.seq = 0
43
44
 
44
45
  this.sendMessage = makeConcurrent(
45
46
  async (method, params = []) => {
46
47
  return new Promise((resolve, reject) => {
47
48
  if (this.isClosed || this.shutdown) return reject(new Error('connection not started'))
48
- const id = Math.floor(Math.random() * 1e7) + 1
49
+ const id = ++this.seq
49
50
 
50
51
  this.rpcQueue[id] = { resolve, reject }
51
52
  this.rpcQueue[id].timeout = setTimeout(() => {
@@ -169,7 +170,7 @@ export class Connection {
169
170
  encoding: 'jsonParsed',
170
171
  },
171
172
  ],
172
- id: 1,
173
+ id: ++this.seq,
173
174
  })
174
175
  )
175
176
  // sub for incoming/outcoming txs
@@ -178,7 +179,7 @@ export class Connection {
178
179
  jsonrpc: '2.0',
179
180
  method: 'logsSubscribe',
180
181
  params: [{ mentions: [address] }, { commitment: 'finalized' }],
181
- id: 2,
182
+ id: ++this.seq,
182
183
  })
183
184
  )
184
185
  })
@@ -219,9 +220,10 @@ export class Connection {
219
220
  clearTimeout(this.pingTimeout)
220
221
  if (this.ws && (this.isConnecting || this.isOpen)) {
221
222
  // this.ws.send(JSON.stringify({ method: 'close' }))
222
- await delay(ms('1s')) // allow for the 'close' round-trip
223
+ // Not sending the method above so just no need to wait below
224
+ // await delay(ms('1s')) // allow for the 'close' round-trip
223
225
  await this.ws.close()
224
- await this.ws.terminate()
226
+ if (this.ws.terminate) await this.ws.terminate()
225
227
  }
226
228
  }
227
229
 
@@ -239,8 +241,6 @@ export class Connection {
239
241
  if (this.shutdown) return
240
242
  this.shutdown = true
241
243
  await this.close()
242
- while (this.running) {
243
- await delay(ms('1s'))
244
- }
244
+ while (this.running) await delay(ms('50ms'))
245
245
  }
246
246
  } // Connection
package/src/index.js CHANGED
@@ -2,21 +2,21 @@ import { connectAssets } from '@exodus/assets'
2
2
  import { keyBy } from '@exodus/basic-utils'
3
3
  import assetsList from '@exodus/solana-meta'
4
4
 
5
- import { Api } from './api'
5
+ import { Api } from './api.js'
6
6
 
7
- export { default as SolanaFeeMonitor } from './fee-monitor'
8
- export { SolanaMonitor, SolanaAutoWithdrawMonitor } from './tx-log'
9
- export { createAccountState } from './account-state'
10
- export { getSolStakedFee, getStakingInfo, getUnstakingFee } from './staking-utils'
7
+ export { default as SolanaFeeMonitor } from './fee-monitor.js'
8
+ export { SolanaMonitor, SolanaAutoWithdrawMonitor } from './tx-log/index.js'
9
+ export { createAccountState } from './account-state.js'
10
+ export { getSolStakedFee, getStakingInfo, getUnstakingFee } from './staking-utils.js'
11
11
  export {
12
12
  isSolanaStaking,
13
13
  isSolanaUnstaking,
14
14
  isSolanaWithdrawn,
15
15
  isSolanaRewardsActivityTx,
16
- } from './txs-utils'
17
- export { createAndBroadcastTXFactory } from './tx-send'
18
- export { getBalancesFactory } from './get-balances'
19
- export { stakingProviderClientFactory } from './staking-provider-client'
16
+ } from './txs-utils.js'
17
+ export { createAndBroadcastTXFactory } from './tx-send.js'
18
+ export { getBalancesFactory } from './get-balances.js'
19
+ export { stakingProviderClientFactory } from './staking-provider-client.js'
20
20
 
21
21
  // These are not the same asset objects as the wallet creates, so they should never be returned to the wallet.
22
22
  // Initially this may be violated by the Solana code until the first monitor tick updates assets with setTokens()
@@ -27,4 +27,4 @@ const assets = connectAssets(keyBy(assetsList, (asset) => asset.name))
27
27
  const serverApi = new Api({ assets })
28
28
  export default serverApi
29
29
 
30
- export { Api } from './api'
30
+ export { Api } from './api.js'
@@ -1,2 +1,2 @@
1
- export * from './solana-monitor'
2
- export * from './solana-auto-withdraw-monitor'
1
+ export * from './solana-monitor.js'
2
+ export * from './solana-auto-withdraw-monitor.js'
@@ -1,8 +1,10 @@
1
1
  import { Timer } from '@exodus/timer'
2
- import assert from 'assert'
3
- import { get } from 'lodash'
2
+ import lodash from 'lodash'
3
+ import assert from 'minimalistic-assert'
4
4
  import ms from 'ms'
5
5
 
6
+ const { get } = lodash
7
+
6
8
  const INTERVAL = ms('30s')
7
9
 
8
10
  export class SolanaAutoWithdrawMonitor {
@@ -3,7 +3,7 @@ import _ from 'lodash'
3
3
  import assert from 'minimalistic-assert'
4
4
  import ms from 'ms'
5
5
 
6
- import { DEFAULT_POOL_ADDRESS } from '../account-state'
6
+ import { DEFAULT_POOL_ADDRESS } from '../account-state.js'
7
7
 
8
8
  const DEFAULT_REMOTE_CONFIG = {
9
9
  rpcs: [],
package/src/tx-send.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  TOKEN_2022_PROGRAM_ID,
6
6
  TOKEN_PROGRAM_ID,
7
7
  } from '@exodus/solana-lib'
8
- import { transactionToBase58 } from '@exodus/solana-lib/src/tx/common'
8
+ import { transactionToBase58 } from '@exodus/solana-lib/src/tx/common.js'
9
9
  import assert from 'minimalistic-assert'
10
10
 
11
11
  export const createAndBroadcastTXFactory =
package/src/txs-utils.js CHANGED
@@ -1,4 +1,6 @@
1
- import { get } from 'lodash'
1
+ import lodash from 'lodash'
2
+
3
+ const { get } = lodash
2
4
 
3
5
  const isSolanaTx = (tx) => tx.coinName === 'solana'
4
6
  export const isSolanaStaking = (tx) =>