@exodus/solana-api 2.0.6 → 2.0.7

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.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "Exodus internal Solana asset API wrapper",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -20,6 +20,7 @@
20
20
  "@exodus/models": "^8.7.2",
21
21
  "@exodus/nfts-core": "^0.5.0",
22
22
  "@exodus/solana-lib": "^1.3.11",
23
+ "bn.js": "^4.11.0",
23
24
  "lodash": "^4.17.11",
24
25
  "url-join": "4.0.0",
25
26
  "wretch": "^1.5.2"
@@ -27,5 +28,5 @@
27
28
  "devDependencies": {
28
29
  "node-fetch": "~2.6.0"
29
30
  },
30
- "gitHead": "de10261779745bb46c3fb0ee03821a3527d1d63b"
31
+ "gitHead": "6c666e0fc0759e60553490c570dd94181dddfd37"
31
32
  }
package/src/api.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // @flow
2
+ import BN from 'bn.js'
2
3
  import createApi from '@exodus/asset-json-rpc'
3
4
  import {
4
5
  getMetadataAccount,
@@ -228,6 +229,58 @@ export class Api {
228
229
  }
229
230
  }
230
231
 
232
+ const getInnerTxsFromBalanceChanges = () => {
233
+ const ownPreTokenBalances = preTokenBalances.filter(
234
+ (balance) => balance.owner === ownerAddress
235
+ )
236
+ const ownPostTokenBalances = postTokenBalances.filter(
237
+ (balance) => balance.owner === ownerAddress
238
+ )
239
+
240
+ return ownPostTokenBalances
241
+ .map((postBalance) => {
242
+ const tokenAccount = tokenAccountsByOwner.find(
243
+ (tokenAccount) => tokenAccount.mintAddress === postBalance.mint
244
+ )
245
+
246
+ const preBalance = ownPreTokenBalances.find(
247
+ (balance) => balance.accountIndex === postBalance.accountIndex
248
+ )
249
+
250
+ const preAmount = new BN(lodash.get(preBalance, 'uiTokenAmount.amount', '0'), 10)
251
+ const postAmount = new BN(lodash.get(postBalance, 'uiTokenAmount.amount', '0'), 10)
252
+
253
+ const amount = postAmount.sub(preAmount)
254
+
255
+ if (!tokenAccount || amount.isZero()) return null
256
+
257
+ // This is not perfect as there could be multiple same-token transfers in single
258
+ // transaction, but our wallet only supports one transaction with single txId
259
+ // so we are picking first that matches (correct token + type - send or receive)
260
+ const { from, to, owner } = innerInstructions.find((inner) => {
261
+ const targetOwner = amount.isNeg() ? ownerAddress : null
262
+ return (
263
+ inner.token.mintAddress === tokenAccount.mintAddress && targetOwner === inner.owner
264
+ )
265
+ })
266
+
267
+ return {
268
+ id: txDetails.transaction.signatures[0],
269
+ slot: txDetails.slot,
270
+ owner,
271
+ from,
272
+ to,
273
+ amount: amount.abs().toNumber(),
274
+ fee: 0,
275
+ token: tokenAccount,
276
+ data: {
277
+ inner: true,
278
+ },
279
+ }
280
+ })
281
+ .filter((ix) => !!ix)
282
+ }
283
+
231
284
  instructions = instructions
232
285
  .filter((ix) => ix.parsed) // only known instructions
233
286
  .map((ix) => ({
@@ -412,7 +465,7 @@ export class Api {
412
465
  // 2. default behavior is not perfect. For example it doesn't see SOL-side tx in
413
466
  // SOL->SPL swaps on Raydium and Orca.
414
467
  tx = getUnparsedTx(tx)
415
- tx.dexTxs = innerInstructions.map((i) => ({ ...i, fee: 0 }))
468
+ tx.dexTxs = getInnerTxsFromBalanceChanges()
416
469
  } else {
417
470
  if (solanaTx) {
418
471
  // the base tx will be the one that moved solana.
@@ -776,6 +829,7 @@ export class Api {
776
829
  collectionId: null,
777
830
  collectionName: null,
778
831
  collectionTitle: null,
832
+ title: null,
779
833
  }
780
834
 
781
835
  // Only perform an NFT check (getSupply) if decimal is zero
@@ -785,11 +839,13 @@ export class Api {
785
839
  id: collectionId,
786
840
  collectionName,
787
841
  collectionTitle,
842
+ title,
788
843
  } = await magicEden.api.getNFTByMintAddress(account.mint)
789
844
  nft = {
790
845
  collectionId,
791
846
  collectionTitle,
792
847
  collectionName,
848
+ title,
793
849
  }
794
850
  tokenMetaPlex.name = tokenMetaPlex.name || collectionTitle
795
851
  tokenMetaPlex.symbol = tokenMetaPlex.symbol || collectionName
@@ -94,6 +94,7 @@ export class SolanaMonitor extends BaseMonitor {
94
94
  data: {
95
95
  staking: tx.staking || null,
96
96
  unparsed: !!tx.unparsed,
97
+ swapTx: !!(tx.data && tx.data.inner),
97
98
  },
98
99
  }
99
100