@exodus/solana-api 3.11.9 → 3.12.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,16 @@
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.12.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.11.9...@exodus/solana-api@3.12.0) (2025-01-02)
7
+
8
+
9
+ ### Features
10
+
11
+
12
+ * feat: reduce call of Solana getTokenAccountsByOwner (#4762)
13
+
14
+
15
+
6
16
  ## [3.11.9](https://github.com/ExodusMovement/assets/compare/@exodus/solana-api@3.11.8...@exodus/solana-api@3.11.9) (2024-12-31)
7
17
 
8
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/solana-api",
3
- "version": "3.11.9",
3
+ "version": "3.12.0",
4
4
  "description": "Transaction monitors, fee monitors, RPC with the blockchain node, and other networking code for Solana",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -47,7 +47,7 @@
47
47
  "@exodus/assets-testing": "^1.0.0",
48
48
  "@exodus/solana-web3.js": "^1.63.1-exodus.9-rc3"
49
49
  },
50
- "gitHead": "44b274a6a6f0228014aa0eaac5af850dcaf76fed",
50
+ "gitHead": "70de901b0d9b85f1045949400105203c700fc223",
51
51
  "bugs": {
52
52
  "url": "https://github.com/ExodusMovement/assets/issues?q=is%3Aissue+is%3Aopen+label%3Asolana-api"
53
53
  },
package/src/api.js CHANGED
@@ -186,7 +186,10 @@ export class Api {
186
186
  /**
187
187
  * Get transactions from an address
188
188
  */
189
- async getTransactions(address, { cursor, before, limit, includeUnparsed = false } = {}) {
189
+ async getTransactions(
190
+ address,
191
+ { cursor, before, limit, includeUnparsed = false, tokenAccounts } = Object.create(null)
192
+ ) {
190
193
  limit = limit || this.txsLimit
191
194
  let transactions = []
192
195
  // cursor is a txHash
@@ -194,7 +197,7 @@ export class Api {
194
197
  try {
195
198
  const until = cursor
196
199
 
197
- const tokenAccountsByOwner = await this.getTokenAccountsByOwner(address) // Array
200
+ const tokenAccountsByOwner = tokenAccounts || (await this.getTokenAccountsByOwner(address)) // Array
198
201
  const tokenAccountAddresses = tokenAccountsByOwner
199
202
  .filter(({ tokenName }) => tokenName !== 'unknown')
200
203
  .map(({ tokenAccountAddress }) => tokenAccountAddress)
@@ -195,6 +195,7 @@ export class SolanaMonitor extends BaseMonitor {
195
195
  accountState,
196
196
  walletAccount,
197
197
  refresh,
198
+ tokenAccounts,
198
199
  })
199
200
 
200
201
  const cursorChanged = this.hasNewCursor({ walletAccount, cursorState })
@@ -210,7 +211,7 @@ export class SolanaMonitor extends BaseMonitor {
210
211
  }
211
212
  }
212
213
 
213
- async getHistory({ address, accountState, refresh } = {}) {
214
+ async getHistory({ address, accountState, refresh, tokenAccounts } = Object.create(null)) {
214
215
  const cursor = refresh ? '' : accountState.cursor
215
216
  const baseAsset = this.asset
216
217
 
@@ -218,6 +219,7 @@ export class SolanaMonitor extends BaseMonitor {
218
219
  cursor,
219
220
  includeUnparsed: this.includeUnparsed,
220
221
  limit: this.txsLimit,
222
+ tokenAccounts,
221
223
  })
222
224
 
223
225
  const mappedTransactions = []
@@ -227,8 +229,7 @@ export class SolanaMonitor extends BaseMonitor {
227
229
  if (assetName === 'unknown' || !asset) continue // skip unknown tokens
228
230
  const feeAsset = asset.feeAsset
229
231
 
230
- // TODO: remove all uses of toDefault()
231
- const coinAmount = asset.currency.baseUnit(tx.amount).toDefault()
232
+ const coinAmount = asset.currency.baseUnit(tx.amount)
232
233
 
233
234
  const item = {
234
235
  coinName: assetName,
@@ -249,7 +250,7 @@ export class SolanaMonitor extends BaseMonitor {
249
250
  if (tx.owner === address) {
250
251
  // send transaction
251
252
  item.to = tx.to
252
- item.feeAmount = baseAsset.currency.baseUnit(tx.fee).toDefault() // in SOL
253
+ item.feeAmount = baseAsset.currency.baseUnit(tx.fee) // in SOL
253
254
  item.feeCoinName = baseAsset.name
254
255
  item.coinAmount = item.coinAmount.negate()
255
256
 
@@ -259,7 +260,7 @@ export class SolanaMonitor extends BaseMonitor {
259
260
  }
260
261
  } else if (tx.unparsed) {
261
262
  if (tx.fee !== 0) {
262
- item.feeAmount = baseAsset.currency.baseUnit(tx.fee).toDefault() // in SOL
263
+ item.feeAmount = baseAsset.currency.baseUnit(tx.fee) // in SOL
263
264
  item.feeCoinName = baseAsset.name
264
265
  }
265
266
 
@@ -308,7 +309,7 @@ export class SolanaMonitor extends BaseMonitor {
308
309
  })
309
310
 
310
311
  const tokenBalances = _.mapValues(splBalances, (balance, name) =>
311
- this.assets[name].currency.baseUnit(balance).toDefault()
312
+ this.assets[name].currency.baseUnit(balance)
312
313
  )
313
314
 
314
315
  const solBalanceChanged = this.#balanceChanged({
@@ -336,7 +337,6 @@ export class SolanaMonitor extends BaseMonitor {
336
337
  .add(stakedBalance)
337
338
  .add(withdrawableBalance)
338
339
  .add(pendingBalance)
339
- .toDefault()
340
340
 
341
341
  return {
342
342
  account: {
@@ -376,11 +376,11 @@ export class SolanaMonitor extends BaseMonitor {
376
376
  isDelegating: Object.values(stakingInfo.accounts).some(({ state }) =>
377
377
  ['active', 'activating', 'inactive'].includes(state)
378
378
  ), // true if at least 1 account is delegating
379
- locked: this.asset.currency.baseUnit(stakingInfo.locked).toDefault(),
379
+ locked: this.asset.currency.baseUnit(stakingInfo.locked),
380
380
  activating: this.asset.currency.baseUnit(stakingInfo.activating),
381
- withdrawable: this.asset.currency.baseUnit(stakingInfo.withdrawable).toDefault(),
382
- pending: this.asset.currency.baseUnit(stakingInfo.pending).toDefault(), // still undelegating (not yet available for withdraw)
383
- earned: this.asset.currency.baseUnit(rewards).toDefault(),
381
+ withdrawable: this.asset.currency.baseUnit(stakingInfo.withdrawable),
382
+ pending: this.asset.currency.baseUnit(stakingInfo.pending), // still undelegating (not yet available for withdraw)
383
+ earned: this.asset.currency.baseUnit(rewards),
384
384
  accounts: stakingInfo.accounts, // Obj
385
385
  }
386
386
  }