UNPKG

solana-dex-parser

Version:

Solana Dex Transaction Parser

94 lines 4.13 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const web3_js_1 = require("@solana/web3.js"); const dotenv_1 = __importDefault(require("dotenv")); const fs = __importStar(require("fs")); const dex_parser_1 = require("../dex-parser"); dotenv_1.default.config(); describe('Parser', () => { let connection; beforeAll(async () => { // Initialize connection const rpcUrl = process.env.SOLANA_RPC_URL; if (!rpcUrl) { throw new Error('SOLANA_RPC_URL environment variable is not set'); } connection = new web3_js_1.Connection(rpcUrl, { commitment: 'confirmed', }); }); describe('Dex', () => { describe('parseTransaction', () => { // it("block", async () => { // const parser = new DexParser(); // const s1 = Date.now(); // const block = await connection.getBlock(333062219, { // commitment: 'confirmed', // maxSupportedTransactionVersion: 0, // transactionDetails: 'full', // }) // const s2 = Date.now(); // if (!block) { // throw new Error("Block not found"); // } // const ts: any[] = [], liqs: any[] = []; // // console.log(block.transactions[0]); // block.transactions.forEach((tx) => { // if (tx.meta?.err) { // return; // } // const { trades, liquidities } = parser.parseAll({ ...tx!, slot: (block.parentSlot + 1), blockTime: block.blockTime } as any, { tryUnknowDEX: false }); // ts.push(...trades); // liqs.push(...liquidities); // }) // const s3 = Date.now(); // console.log(`Fetch block: ${(s2 - s1) / 1000} s > Parser: ${(s3 - s2) / 1000} s > Hits: ${ts.length + liqs.length} / ${block.transactions.length}`); // }); it("json-block", async () => { const parser = new dex_parser_1.DexParser(); const data = fs.readFileSync("./src/__tests__/tx-55gZaGoRSov1S9yQE3azRhteZrxwswk9YWW4E7z3XBBaLL9VFdoMnJTYfcixGXJTpp2yGmuCznqw8tj78E9po8UC.json", { encoding: "utf8" }); const tx = JSON.parse(data); const { trades, liquidities } = parser.parseAll(tx, { tryUnknowDEX: false }); console.log('trades', trades); console.log('liquidities', liquidities); }); }); }); }); //# sourceMappingURL=parser-block.test.js.map