-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# 🚀 solana-txn-parser | ||
|
||
An open-source transaction parser for popular DeFi applications on the Solana blockchain, written in TypeScript. | ||
|
||
## 💪🏽 Supported DeFi Platforms | ||
|
||
- PumpFun ✅ | ||
- Raydium 🔜 | ||
- Jupiter 🔜 | ||
|
||
## 👨🔧 Installation | ||
|
||
```bash | ||
npm install git+https://github.com/Tee-py/solana-txn-parser.git | ||
``` | ||
|
||
## 👨🏽💻 Usage | ||
|
||
### PumpFun Parser | ||
|
||
```typescript | ||
import { PumpFunParser } from 'solana-txn-parser'; | ||
import { Connection, PublicKey, clusterApiUrl, ParsedTransactionWithMeta } from '@solana/web3.js'; | ||
import fs from "fs"; | ||
|
||
const connection = new Connection(clusterApiUrl('mainnet-beta')); | ||
const parser = new PumpFunParser(); | ||
|
||
// Fetch a transaction | ||
const txnSig = '<transaction_signature>' | ||
const txn1 = await connection.getParsedTransaction(txnSig); | ||
|
||
// Parse single transaction | ||
const pumpTxn = parser.parse(transaction); | ||
console.log(parsedTx); | ||
|
||
// Parse multiple transactions | ||
const txnSig2 = '<second transaction signature>' | ||
const txn2 = await connection.getParsedTransaction(txnSig2) | ||
const pumpTxns = parser.parseMultiple([txn1, txn2]) | ||
|
||
// Parse transaction from json file | ||
const txn = JSON.parse(fs.readFileSync("<file_path>", "utf-8")) as unknown as ParsedTransactionWithMeta | ||
const pumpTxn = parser.parse(txn) | ||
``` | ||
|
||
### Raydium Parser [Comming soon] | ||
|
||
### Jupiter Parser [Coming soon] | ||
|
||
### Creating Custom Parsers | ||
|
||
You can create custom parsers for other DeFi platforms by extending the `BaseParser` class: | ||
|
||
```typescript | ||
import { BaseParser, ParsedTransactionWithMeta } from 'solana-txn-parser'; | ||
|
||
interface CustomTransaction { | ||
// Define your custom transaction structure | ||
} | ||
|
||
class CustomParser extends BaseParser<CustomTransaction> { | ||
parse(transaction: ParsedTransactionWithMeta): CustomTransaction { | ||
// Implement your parsing logic here | ||
} | ||
|
||
parseMultiple(transactions: ParsedTransactionWithMeta[]): CustomTransaction[] { | ||
return transactions.map(tx => this.parse(tx)); | ||
} | ||
} | ||
``` | ||
|
||
## 🤝 Contributing | ||
|
||
Here's how you can contribute to the library: | ||
|
||
### 🎉 Adding a New Parser | ||
|
||
- Fork the repository and create a new branch for your parser. | ||
- Create a new folder in the `src/parsers` directory for your parser (e.g., `newparser`). | ||
- Add an index.ts file in the `src/parser/<newparser>` directory to hold your Parser logic | ||
- Implement your parser by extending the `BaseParser` class. | ||
- Write unit tests for your parser in the `tests/newparser` directory. | ||
- Update the README.md to include documentation for your new parser. | ||
- Submit a pull request with your changes. | ||
|
||
You can check the parser directory for more information on how to implement your new parser | ||
|
||
### ♻️ Modifying/Improving Existing Parsers | ||
|
||
- Fork the repository and create a new branch for your modifications. | ||
- Make your changes to the existing parser file. | ||
- If you're adding new functionality, make sure to add corresponding unit tests. | ||
- If you're fixing a bug, add a test case that would have caught the bug. | ||
- Update the README.md if your changes affect the usage of the parser. | ||
- Submit a pull request with your changes, explaining the modifications and their purpose. | ||
|
||
For all contributions, please ensure your code passes all existing tests. You can also help in improving the tests for the existing parsers. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |