@exodus/solana-api 1.4.8 → 2.0.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +44 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/solana-api",
3
- "version": "1.4.8",
3
+ "version": "2.0.0",
4
4
  "description": "Exodus internal Solana asset API wrapper",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -22,5 +22,5 @@
22
22
  "devDependencies": {
23
23
  "node-fetch": "~1.6.3"
24
24
  },
25
- "gitHead": "90293962539f80a74060b3010cbfa4ab4570baa7"
25
+ "gitHead": "d2b02ce96a053e1475edbcad3b9d304b0a2fbe92"
26
26
  }
package/src/index.js CHANGED
@@ -27,6 +27,7 @@ class Api {
27
27
  constructor(rpcUrl) {
28
28
  this.setServer(rpcUrl)
29
29
  this.setTokens(assets)
30
+ this.tokensToSkip = {}
30
31
  }
31
32
 
32
33
  setServer(rpcUrl) {
@@ -219,6 +220,9 @@ class Api {
219
220
  unparsed: true,
220
221
  amount: postBalances[ownerIndex] - preBalances[ownerIndex] + feePaid,
221
222
  fee: feePaid,
223
+ data: {
224
+ meta: txDetails.meta,
225
+ },
222
226
  }
223
227
  }
224
228
 
@@ -453,6 +457,36 @@ class Api {
453
457
  }
454
458
  }
455
459
 
460
+ async getSupply(mintAddress: string): string {
461
+ const { value: { amount } } = await this.api.post({
462
+ method: 'getTokenSupply',
463
+ params: [mintAddress],
464
+ })
465
+ return amount
466
+ }
467
+
468
+ async getWalletTokensList({ address, tokenAccounts }) {
469
+ const tokensMint = []
470
+ for (let account of tokenAccounts) {
471
+ const mint = account.mintAddress
472
+
473
+ // skip cached NFT
474
+ if (this.tokensToSkip[mint]) continue
475
+ // skip 0 balance
476
+ if (account.balance === '0') continue
477
+ // skip NFT
478
+ const supply = await this.getSupply(mint)
479
+ if (supply === '1') {
480
+ this.tokensToSkip[mint] = true
481
+ continue
482
+ }
483
+ // OK
484
+ tokensMint.push(mint)
485
+ }
486
+
487
+ return tokensMint
488
+ }
489
+
456
490
  async getTokenAccountsByOwner(address: string, tokenTicker: ?string): Array {
457
491
  const { value: accountsList } = await this.api.post({
458
492
  method: 'getTokenAccountsByOwner',
@@ -484,8 +518,8 @@ class Api {
484
518
  : tokenAccounts
485
519
  }
486
520
 
487
- async getTokensBalance(address: string, filterByTokens = []) {
488
- let accounts = await this.getTokenAccountsByOwner(address) // Tokens
521
+ async getTokensBalance({ address, filterByTokens = [], tokenAccounts }) {
522
+ let accounts = tokenAccounts || (await this.getTokenAccountsByOwner(address))
489
523
 
490
524
  const tokensBalance = accounts.reduce((acc, { tokenName, balance }) => {
491
525
  if (tokenName === 'unknown' || (filterByTokens.length && !filterByTokens.includes(tokenName)))
@@ -532,6 +566,11 @@ class Api {
532
566
  return value
533
567
  }
534
568
 
569
+ async isSpl(address: string) {
570
+ const { owner } = await this.getAccountInfo(address)
571
+ return owner === 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
572
+ }
573
+
535
574
  async getMetaplexMetadata(tokenMintAddress: string) {
536
575
  const metaplexPDA = getMetadataAccount(tokenMintAddress)
537
576
  const res = await this.getAccountInfo(metaplexPDA)
@@ -751,7 +790,9 @@ class Api {
751
790
  */
752
791
  simulateAndRetrieveSideEffects = async (transactionMessage, publicKey: string) => {
753
792
  const { config, accountAddresses } = getTransactionSimulationParams(transactionMessage)
754
- const encodedTransaction = buildRawTransaction(transactionMessage.serialize()).toString('base64')
793
+ const encodedTransaction = buildRawTransaction(transactionMessage.serialize()).toString(
794
+ 'base64'
795
+ )
755
796
  const futureAccountsState = await this.simulateTransaction(encodedTransaction, config)
756
797
  const { solAccounts, tokenAccounts } = filterAccountsByOwner(
757
798
  futureAccountsState,