@exodus/solana-api 1.4.8 → 2.0.1
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 +3 -3
- package/src/index.js +47 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Exodus internal Solana asset API wrapper",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@exodus/asset-json-rpc": "^1.0.0",
|
|
17
|
-
"@exodus/solana-lib": "^1.3.
|
|
17
|
+
"@exodus/solana-lib": "^1.3.6",
|
|
18
18
|
"lodash": "^4.17.11",
|
|
19
19
|
"url-join": "4.0.0",
|
|
20
20
|
"wretch": "^1.5.2"
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"node-fetch": "~1.6.3"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "90859f94717cf2b928cb93b030ecfba523b8179e"
|
|
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
|
|
488
|
-
let accounts = await this.getTokenAccountsByOwner(address)
|
|
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)
|
|
@@ -560,8 +599,8 @@ class Api {
|
|
|
560
599
|
return account.owner === SYSTEM_PROGRAM_ID.toBase58()
|
|
561
600
|
? 'solana'
|
|
562
601
|
: account.owner === TOKEN_PROGRAM_ID.toBase58()
|
|
563
|
-
|
|
564
|
-
|
|
602
|
+
? 'token'
|
|
603
|
+
: null
|
|
565
604
|
}
|
|
566
605
|
|
|
567
606
|
async getTokenAddressOwner(address: string) {
|
|
@@ -751,7 +790,10 @@ class Api {
|
|
|
751
790
|
*/
|
|
752
791
|
simulateAndRetrieveSideEffects = async (transactionMessage, publicKey: string) => {
|
|
753
792
|
const { config, accountAddresses } = getTransactionSimulationParams(transactionMessage)
|
|
754
|
-
const encodedTransaction = buildRawTransaction(
|
|
793
|
+
const encodedTransaction = buildRawTransaction(
|
|
794
|
+
transactionMessage.serialize(),
|
|
795
|
+
transactionMessage.header.numRequiredSignatures || 1
|
|
796
|
+
).toString('base64')
|
|
755
797
|
const futureAccountsState = await this.simulateTransaction(encodedTransaction, config)
|
|
756
798
|
const { solAccounts, tokenAccounts } = filterAccountsByOwner(
|
|
757
799
|
futureAccountsState,
|