Skip to content

Commit

Permalink
Merge pull request #7 from elsoul/feature
Browse files Browse the repository at this point in the history
add getSolTransferDetails
  • Loading branch information
POPPIN-FUMI authored Dec 5, 2023
2 parents d88a718 + 6ecf964 commit 17ae2d7
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 89 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ firebase-debug.log
/apps/
keyfile.json

/functions/
/functions/
/data/
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.3.1
20.10.0
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export { delegateStake } from './lib/delegateStake'
export { getAllStakeRewardsByPubkey } from './lib/getAllStakeRewardsByPubkey'
export { getCurrentEpoch } from './lib/getCurrentEpoch'
export { createStakeAccount } from './lib/createStakeAccount'
export { getTokenTransferDetails } from './lib/getTokenTransferDetails'
export { getSolTransferDetails } from './lib/getSolTransferDetails'
export { getSPLTransferHistory } from './lib/getSPLTransferHistory'
export type * from './solanaUtilsTypes'
export { MAGIC_EDEN_ADDRESS } from './lib/getMagicEdenOwner'
Expand Down
2 changes: 2 additions & 0 deletions src/lib/getSPLTransferHistory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Connection, PublicKey, ConfirmedSignatureInfo } from '@solana/web3.js'
import { writeFileSync } from 'fs'
import { exit } from 'process'

/**
* Fetches the SPL Transfer history for a given wallet address.
Expand Down
45 changes: 45 additions & 0 deletions src/lib/getSolTransferDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Connection, TransactionSignature } from '@solana/web3.js'
import {
SPLTransferHistoryResponse,
SolTransferDetailsResponse,
SolanaTransaction,
TokenExchange,
} from '..'

/**
* Fetches the details of a transaction, specifically the token transfer details.
*
* @param rpcUrl - The URL of the Solana RPC endpoint.
* @param signature - The transaction signature.
* @returns {Promise<SolTransferDetailsResponse>} - A promise that resolves with the token transfer details.
*
* @example
* ```typescript
* const rpcUrl = 'https://api.mainnet-beta.solana.com';
* const signature = '5verv...'; // Example transaction signature
*
* const transferDetails = await getTokenTransferDetails(rpcUrl, signature);
* console.log(transferDetails);
* ```
*/
export const getSolTransferDetails = async (
rpcUrl: string,
signature: TransactionSignature,
) => {
try {
const connection = new Connection(rpcUrl)

const transactionDetails = (await connection.getParsedTransaction(
signature,
)) as unknown as SolanaTransaction

const tokenTransferDetails =
transactionDetails.transaction.message.instructions.find(
(instruction) => instruction?.parsed?.type === 'transfer',
)?.parsed?.info

return tokenTransferDetails as SolTransferDetailsResponse
} catch (error) {
throw new Error(`getSolTransferDetails: ${error}`)
}
}
86 changes: 0 additions & 86 deletions src/lib/getTokenTransferDetails.ts

This file was deleted.

15 changes: 15 additions & 0 deletions src/solanaUtilsTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,18 @@ export type TokenExchange = {
token2: string
token2Amount: number
}

export type SPLTransferHistoryResponse = {
blockTime: number
confirmationStatus: string
err: null | any
memo: null | string
signature: string
slot: number
}

export type SolTransferDetailsResponse = {
destination: string
lamports: number
source: string
}

0 comments on commit 17ae2d7

Please sign in to comment.