@exodus/solana-api 2.0.5 → 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 +4 -3
- package/src/api.js +57 -3
- package/src/index.js +6 -0
- package/src/tx-log/solana-monitor.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-api",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "Exodus internal Solana asset API wrapper",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"@exodus/assets-base": "^8.0.139",
|
|
20
20
|
"@exodus/models": "^8.7.2",
|
|
21
21
|
"@exodus/nfts-core": "^0.5.0",
|
|
22
|
-
"@exodus/solana-lib": "^1.3.
|
|
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": "
|
|
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 =
|
|
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
|
|
@@ -859,5 +915,3 @@ export class Api {
|
|
|
859
915
|
return this.resolveSimulationSideEffects(solAccounts, tokenAccounts)
|
|
860
916
|
}
|
|
861
917
|
}
|
|
862
|
-
|
|
863
|
-
export default new Api()
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { Api } from './api'
|
|
1
2
|
export * from './api'
|
|
2
3
|
export * from './tx-log'
|
|
3
4
|
export * from './account-state'
|
|
5
|
+
|
|
6
|
+
// At some point we would like to exclude this export. Default export should be the whole asset "plugin" ready to be injected.
|
|
7
|
+
// Clients should not call an specific server api directly.
|
|
8
|
+
const serverApi = new Api()
|
|
9
|
+
export default serverApi
|