tsc & prettier

This commit is contained in:
Filip Dunder
2024-04-30 10:54:57 -03:00
parent 04e5ca7d27
commit 4fcf5165d5
56 changed files with 2860 additions and 791 deletions

View File

@ -0,0 +1,44 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultTransactionExecutor = void 0;
const helpers_1 = require("../helpers");
class DefaultTransactionExecutor {
constructor(connection) {
this.connection = connection;
}
executeAndConfirm(transaction, payer, latestBlockhash) {
return __awaiter(this, void 0, void 0, function* () {
helpers_1.logger.debug("Executing transaction...");
const signature = yield this.execute(transaction);
helpers_1.logger.debug({ signature }, "Confirming transaction...");
return this.confirm(signature, latestBlockhash);
});
}
execute(transaction) {
return __awaiter(this, void 0, void 0, function* () {
return this.connection.sendRawTransaction(transaction.serialize(), {
preflightCommitment: this.connection.commitment,
});
});
}
confirm(signature, latestBlockhash) {
return __awaiter(this, void 0, void 0, function* () {
const confirmation = yield this.connection.confirmTransaction({
signature,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
blockhash: latestBlockhash.blockhash,
}, this.connection.commitment);
return { confirmed: !confirmation.value.err, signature };
});
}
}
exports.DefaultTransactionExecutor = DefaultTransactionExecutor;

View File

@ -1,44 +1,44 @@
import {
BlockhashWithExpiryBlockHeight,
Connection,
Keypair,
Transaction,
VersionedTransaction,
} from '@solana/web3.js';
import { TransactionExecutor } from './transaction-executor.interface';
import { logger } from '../helpers';
BlockhashWithExpiryBlockHeight,
Connection,
Keypair,
Transaction,
VersionedTransaction,
} from "@solana/web3.js";
import { TransactionExecutor } from "./transaction-executor.interface";
import { logger } from "../helpers";
export class DefaultTransactionExecutor implements TransactionExecutor {
constructor(private readonly connection: Connection) {}
constructor(private readonly connection: Connection) {}
public async executeAndConfirm(
transaction: VersionedTransaction,
payer: Keypair,
latestBlockhash: BlockhashWithExpiryBlockHeight,
): Promise<{ confirmed: boolean; signature?: string, error?: string }> {
logger.debug('Executing transaction...');
const signature = await this.execute(transaction);
public async executeAndConfirm(
transaction: VersionedTransaction,
payer: Keypair,
latestBlockhash: BlockhashWithExpiryBlockHeight,
): Promise<{ confirmed: boolean; signature?: string; error?: string }> {
logger.debug("Executing transaction...");
const signature = await this.execute(transaction);
logger.debug({ signature }, 'Confirming transaction...');
return this.confirm(signature, latestBlockhash);
}
logger.debug({ signature }, "Confirming transaction...");
return this.confirm(signature, latestBlockhash);
}
private async execute(transaction: Transaction | VersionedTransaction) {
return this.connection.sendRawTransaction(transaction.serialize(), {
preflightCommitment: this.connection.commitment,
});
}
private async execute(transaction: Transaction | VersionedTransaction) {
return this.connection.sendRawTransaction(transaction.serialize(), {
preflightCommitment: this.connection.commitment,
});
}
private async confirm(signature: string, latestBlockhash: BlockhashWithExpiryBlockHeight) {
const confirmation = await this.connection.confirmTransaction(
{
signature,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
blockhash: latestBlockhash.blockhash,
},
this.connection.commitment,
);
private async confirm(signature: string, latestBlockhash: BlockhashWithExpiryBlockHeight) {
const confirmation = await this.connection.confirmTransaction(
{
signature,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
blockhash: latestBlockhash.blockhash,
},
this.connection.commitment,
);
return { confirmed: !confirmation.value.err, signature };
}
return { confirmed: !confirmation.value.err, signature };
}
}

18
transactions/index.js Normal file
View File

@ -0,0 +1,18 @@
"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 __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./default-transaction-executor"), exports);
__exportStar(require("./transaction-executor.interface"), exports);

View File

@ -1,2 +1,2 @@
export * from './default-transaction-executor';
export * from './transaction-executor.interface';
export * from "./default-transaction-executor";
export * from "./transaction-executor.interface";

View File

@ -0,0 +1,139 @@
"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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JitoTransactionExecutor = void 0;
const web3_js_1 = require("@solana/web3.js");
const helpers_1 = require("../helpers");
const axios_1 = __importStar(require("axios"));
const bs58_1 = __importDefault(require("bs58"));
const raydium_sdk_1 = require("@raydium-io/raydium-sdk");
class JitoTransactionExecutor {
constructor(jitoFee, connection) {
this.jitoFee = jitoFee;
this.connection = connection;
// https://jito-labs.gitbook.io/mev/searcher-resources/json-rpc-api-reference/bundles/gettipaccounts
this.jitpTipAccounts = [
"Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY",
"DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL",
"96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5",
"3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT",
"HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe",
"ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49",
"ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt",
"DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh",
];
this.JitoFeeWallet = this.getRandomValidatorKey();
}
getRandomValidatorKey() {
const randomValidator = this.jitpTipAccounts[Math.floor(Math.random() * this.jitpTipAccounts.length)];
return new web3_js_1.PublicKey(randomValidator);
}
executeAndConfirm(transaction, payer, latestBlockhash) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
helpers_1.logger.debug("Starting Jito transaction execution...");
this.JitoFeeWallet = this.getRandomValidatorKey(); // Update wallet key each execution
helpers_1.logger.trace(`Selected Jito fee wallet: ${this.JitoFeeWallet.toBase58()}`);
try {
const fee = new raydium_sdk_1.CurrencyAmount(raydium_sdk_1.Currency.SOL, this.jitoFee, false).raw.toNumber();
helpers_1.logger.trace(`Calculated fee: ${fee} lamports`);
const jitTipTxFeeMessage = new web3_js_1.TransactionMessage({
payerKey: payer.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: [
web3_js_1.SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: this.JitoFeeWallet,
lamports: fee,
}),
],
}).compileToV0Message();
const jitoFeeTx = new web3_js_1.VersionedTransaction(jitTipTxFeeMessage);
jitoFeeTx.sign([payer]);
const jitoTxsignature = bs58_1.default.encode(jitoFeeTx.signatures[0]);
// Serialize the transactions once here
const serializedjitoFeeTx = bs58_1.default.encode(jitoFeeTx.serialize());
const serializedTransaction = bs58_1.default.encode(transaction.serialize());
const serializedTransactions = [serializedjitoFeeTx, serializedTransaction];
// https://jito-labs.gitbook.io/mev/searcher-resources/json-rpc-api-reference/url
const endpoints = [
"https://mainnet.block-engine.jito.wtf/api/v1/bundles",
"https://amsterdam.mainnet.block-engine.jito.wtf/api/v1/bundles",
"https://frankfurt.mainnet.block-engine.jito.wtf/api/v1/bundles",
"https://ny.mainnet.block-engine.jito.wtf/api/v1/bundles",
"https://tokyo.mainnet.block-engine.jito.wtf/api/v1/bundles",
];
const requests = endpoints.map((url) => axios_1.default.post(url, {
jsonrpc: "2.0",
id: 1,
method: "sendBundle",
params: [serializedTransactions],
}));
helpers_1.logger.trace("Sending transactions to endpoints...");
const results = yield Promise.all(requests.map((p) => p.catch((e) => e)));
const successfulResults = results.filter((result) => !(result instanceof Error));
if (successfulResults.length > 0) {
helpers_1.logger.trace(`At least one successful response`);
helpers_1.logger.debug(`Confirming jito transaction...`);
return yield this.confirm(jitoTxsignature, latestBlockhash);
}
else {
helpers_1.logger.debug(`No successful responses received for jito`);
}
return { confirmed: false };
}
catch (error) {
if (error instanceof axios_1.AxiosError) {
helpers_1.logger.trace({ error: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data }, "Failed to execute jito transaction");
}
helpers_1.logger.error("Error during transaction execution", error);
return { confirmed: false };
}
});
}
confirm(signature, latestBlockhash) {
return __awaiter(this, void 0, void 0, function* () {
const confirmation = yield this.connection.confirmTransaction({
signature,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
blockhash: latestBlockhash.blockhash,
}, this.connection.commitment);
return { confirmed: !confirmation.value.err, signature };
});
}
}
exports.JitoTransactionExecutor = JitoTransactionExecutor;

View File

@ -1,131 +1,131 @@
import {
BlockhashWithExpiryBlockHeight,
Keypair,
PublicKey,
SystemProgram,
Connection,
TransactionMessage,
VersionedTransaction,
} from '@solana/web3.js';
import { TransactionExecutor } from './transaction-executor.interface';
import { logger } from '../helpers';
import axios, { AxiosError } from 'axios';
import bs58 from 'bs58';
import { Currency, CurrencyAmount } from '@raydium-io/raydium-sdk';
BlockhashWithExpiryBlockHeight,
Keypair,
PublicKey,
SystemProgram,
Connection,
TransactionMessage,
VersionedTransaction,
} from "@solana/web3.js";
import { TransactionExecutor } from "./transaction-executor.interface";
import { logger } from "../helpers";
import axios, { AxiosError } from "axios";
import bs58 from "bs58";
import { Currency, CurrencyAmount } from "@raydium-io/raydium-sdk";
export class JitoTransactionExecutor implements TransactionExecutor {
// https://jito-labs.gitbook.io/mev/searcher-resources/json-rpc-api-reference/bundles/gettipaccounts
private jitpTipAccounts = [
'Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY',
'DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL',
'96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5',
'3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT',
'HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe',
'ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49',
'ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt',
'DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh',
];
// https://jito-labs.gitbook.io/mev/searcher-resources/json-rpc-api-reference/bundles/gettipaccounts
private jitpTipAccounts = [
"Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY",
"DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL",
"96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5",
"3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT",
"HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe",
"ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49",
"ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt",
"DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh",
];
private JitoFeeWallet: PublicKey;
private JitoFeeWallet: PublicKey;
constructor(
private readonly jitoFee: string,
private readonly connection: Connection,
) {
this.JitoFeeWallet = this.getRandomValidatorKey();
}
constructor(
private readonly jitoFee: string,
private readonly connection: Connection,
) {
this.JitoFeeWallet = this.getRandomValidatorKey();
}
private getRandomValidatorKey(): PublicKey {
const randomValidator = this.jitpTipAccounts[Math.floor(Math.random() * this.jitpTipAccounts.length)];
return new PublicKey(randomValidator);
}
private getRandomValidatorKey(): PublicKey {
const randomValidator = this.jitpTipAccounts[Math.floor(Math.random() * this.jitpTipAccounts.length)];
return new PublicKey(randomValidator);
}
public async executeAndConfirm(
transaction: VersionedTransaction,
payer: Keypair,
latestBlockhash: BlockhashWithExpiryBlockHeight,
): Promise<{ confirmed: boolean; signature?: string; error?: string }> {
logger.debug('Starting Jito transaction execution...');
this.JitoFeeWallet = this.getRandomValidatorKey(); // Update wallet key each execution
logger.trace(`Selected Jito fee wallet: ${this.JitoFeeWallet.toBase58()}`);
public async executeAndConfirm(
transaction: VersionedTransaction,
payer: Keypair,
latestBlockhash: BlockhashWithExpiryBlockHeight,
): Promise<{ confirmed: boolean; signature?: string; error?: string }> {
logger.debug("Starting Jito transaction execution...");
this.JitoFeeWallet = this.getRandomValidatorKey(); // Update wallet key each execution
logger.trace(`Selected Jito fee wallet: ${this.JitoFeeWallet.toBase58()}`);
try {
const fee = new CurrencyAmount(Currency.SOL, this.jitoFee, false).raw.toNumber();
logger.trace(`Calculated fee: ${fee} lamports`);
try {
const fee = new CurrencyAmount(Currency.SOL, this.jitoFee, false).raw.toNumber();
logger.trace(`Calculated fee: ${fee} lamports`);
const jitTipTxFeeMessage = new TransactionMessage({
payerKey: payer.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: [
SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: this.JitoFeeWallet,
lamports: fee,
}),
],
}).compileToV0Message();
const jitTipTxFeeMessage = new TransactionMessage({
payerKey: payer.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: [
SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: this.JitoFeeWallet,
lamports: fee,
}),
],
}).compileToV0Message();
const jitoFeeTx = new VersionedTransaction(jitTipTxFeeMessage);
jitoFeeTx.sign([payer]);
const jitoFeeTx = new VersionedTransaction(jitTipTxFeeMessage);
jitoFeeTx.sign([payer]);
const jitoTxsignature = bs58.encode(jitoFeeTx.signatures[0]);
const jitoTxsignature = bs58.encode(jitoFeeTx.signatures[0]);
// Serialize the transactions once here
const serializedjitoFeeTx = bs58.encode(jitoFeeTx.serialize());
const serializedTransaction = bs58.encode(transaction.serialize());
const serializedTransactions = [serializedjitoFeeTx, serializedTransaction];
// Serialize the transactions once here
const serializedjitoFeeTx = bs58.encode(jitoFeeTx.serialize());
const serializedTransaction = bs58.encode(transaction.serialize());
const serializedTransactions = [serializedjitoFeeTx, serializedTransaction];
// https://jito-labs.gitbook.io/mev/searcher-resources/json-rpc-api-reference/url
const endpoints = [
'https://mainnet.block-engine.jito.wtf/api/v1/bundles',
'https://amsterdam.mainnet.block-engine.jito.wtf/api/v1/bundles',
'https://frankfurt.mainnet.block-engine.jito.wtf/api/v1/bundles',
'https://ny.mainnet.block-engine.jito.wtf/api/v1/bundles',
'https://tokyo.mainnet.block-engine.jito.wtf/api/v1/bundles',
];
// https://jito-labs.gitbook.io/mev/searcher-resources/json-rpc-api-reference/url
const endpoints = [
"https://mainnet.block-engine.jito.wtf/api/v1/bundles",
"https://amsterdam.mainnet.block-engine.jito.wtf/api/v1/bundles",
"https://frankfurt.mainnet.block-engine.jito.wtf/api/v1/bundles",
"https://ny.mainnet.block-engine.jito.wtf/api/v1/bundles",
"https://tokyo.mainnet.block-engine.jito.wtf/api/v1/bundles",
];
const requests = endpoints.map((url) =>
axios.post(url, {
jsonrpc: '2.0',
id: 1,
method: 'sendBundle',
params: [serializedTransactions],
}),
);
const requests = endpoints.map((url) =>
axios.post(url, {
jsonrpc: "2.0",
id: 1,
method: "sendBundle",
params: [serializedTransactions],
}),
);
logger.trace('Sending transactions to endpoints...');
const results = await Promise.all(requests.map((p) => p.catch((e) => e)));
logger.trace("Sending transactions to endpoints...");
const results = await Promise.all(requests.map((p) => p.catch((e) => e)));
const successfulResults = results.filter((result) => !(result instanceof Error));
const successfulResults = results.filter((result) => !(result instanceof Error));
if (successfulResults.length > 0) {
logger.trace(`At least one successful response`);
logger.debug(`Confirming jito transaction...`);
return await this.confirm(jitoTxsignature, latestBlockhash);
} else {
logger.debug(`No successful responses received for jito`);
}
if (successfulResults.length > 0) {
logger.trace(`At least one successful response`);
logger.debug(`Confirming jito transaction...`);
return await this.confirm(jitoTxsignature, latestBlockhash);
} else {
logger.debug(`No successful responses received for jito`);
}
return { confirmed: false };
} catch (error) {
if (error instanceof AxiosError) {
logger.trace({ error: error.response?.data }, 'Failed to execute jito transaction');
}
logger.error('Error during transaction execution', error);
return { confirmed: false };
}
}
return { confirmed: false };
} catch (error) {
if (error instanceof AxiosError) {
logger.trace({ error: error.response?.data }, "Failed to execute jito transaction");
}
logger.error("Error during transaction execution", error);
return { confirmed: false };
}
}
private async confirm(signature: string, latestBlockhash: BlockhashWithExpiryBlockHeight) {
const confirmation = await this.connection.confirmTransaction(
{
signature,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
blockhash: latestBlockhash.blockhash,
},
this.connection.commitment,
);
private async confirm(signature: string, latestBlockhash: BlockhashWithExpiryBlockHeight) {
const confirmation = await this.connection.confirmTransaction(
{
signature,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
blockhash: latestBlockhash.blockhash,
},
this.connection.commitment,
);
return { confirmed: !confirmation.value.err, signature };
}
return { confirmed: !confirmation.value.err, signature };
}
}

View File

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@ -1,9 +1,9 @@
import { BlockhashWithExpiryBlockHeight, Keypair, VersionedTransaction } from '@solana/web3.js';
import { BlockhashWithExpiryBlockHeight, Keypair, VersionedTransaction } from "@solana/web3.js";
export interface TransactionExecutor {
executeAndConfirm(
transaction: VersionedTransaction,
payer: Keypair,
latestBlockHash: BlockhashWithExpiryBlockHeight,
): Promise<{ confirmed: boolean; signature?: string, error?: string }>;
executeAndConfirm(
transaction: VersionedTransaction,
payer: Keypair,
latestBlockHash: BlockhashWithExpiryBlockHeight,
): Promise<{ confirmed: boolean; signature?: string; error?: string }>;
}

View File

@ -0,0 +1,85 @@
"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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WarpTransactionExecutor = void 0;
const web3_js_1 = require("@solana/web3.js");
const helpers_1 = require("../helpers");
const axios_1 = __importStar(require("axios"));
const bs58_1 = __importDefault(require("bs58"));
const raydium_sdk_1 = require("@raydium-io/raydium-sdk");
class WarpTransactionExecutor {
constructor(warpFee) {
this.warpFee = warpFee;
this.warpFeeWallet = new web3_js_1.PublicKey("WARPzUMPnycu9eeCZ95rcAUxorqpBqHndfV3ZP5FSyS");
}
executeAndConfirm(transaction, payer, latestBlockhash) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
helpers_1.logger.debug("Executing transaction...");
try {
const fee = new raydium_sdk_1.CurrencyAmount(raydium_sdk_1.Currency.SOL, this.warpFee, false).raw.toNumber();
const warpFeeMessage = new web3_js_1.TransactionMessage({
payerKey: payer.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: [
web3_js_1.SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: this.warpFeeWallet,
lamports: fee,
}),
],
}).compileToV0Message();
const warpFeeTx = new web3_js_1.VersionedTransaction(warpFeeMessage);
warpFeeTx.sign([payer]);
const response = yield axios_1.default.post("https://tx.warp.id/transaction/execute", {
transactions: [bs58_1.default.encode(warpFeeTx.serialize()), bs58_1.default.encode(transaction.serialize())],
latestBlockhash,
}, {
timeout: 100000,
});
return response.data;
}
catch (error) {
if (error instanceof axios_1.AxiosError) {
helpers_1.logger.trace({ error: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data }, "Failed to execute warp transaction");
}
}
return { confirmed: false };
});
}
}
exports.WarpTransactionExecutor = WarpTransactionExecutor;

View File

@ -1,64 +1,64 @@
import {
BlockhashWithExpiryBlockHeight,
Keypair,
PublicKey,
SystemProgram,
TransactionMessage,
VersionedTransaction,
} from '@solana/web3.js';
import { TransactionExecutor } from './transaction-executor.interface';
import { logger } from '../helpers';
import axios, { AxiosError } from 'axios';
import bs58 from 'bs58';
import { Currency, CurrencyAmount } from '@raydium-io/raydium-sdk';
BlockhashWithExpiryBlockHeight,
Keypair,
PublicKey,
SystemProgram,
TransactionMessage,
VersionedTransaction,
} from "@solana/web3.js";
import { TransactionExecutor } from "./transaction-executor.interface";
import { logger } from "../helpers";
import axios, { AxiosError } from "axios";
import bs58 from "bs58";
import { Currency, CurrencyAmount } from "@raydium-io/raydium-sdk";
export class WarpTransactionExecutor implements TransactionExecutor {
private readonly warpFeeWallet = new PublicKey('WARPzUMPnycu9eeCZ95rcAUxorqpBqHndfV3ZP5FSyS');
private readonly warpFeeWallet = new PublicKey("WARPzUMPnycu9eeCZ95rcAUxorqpBqHndfV3ZP5FSyS");
constructor(private readonly warpFee: string) {}
constructor(private readonly warpFee: string) {}
public async executeAndConfirm(
transaction: VersionedTransaction,
payer: Keypair,
latestBlockhash: BlockhashWithExpiryBlockHeight,
): Promise<{ confirmed: boolean; signature?: string; error?: string }> {
logger.debug('Executing transaction...');
public async executeAndConfirm(
transaction: VersionedTransaction,
payer: Keypair,
latestBlockhash: BlockhashWithExpiryBlockHeight,
): Promise<{ confirmed: boolean; signature?: string; error?: string }> {
logger.debug("Executing transaction...");
try {
const fee = new CurrencyAmount(Currency.SOL, this.warpFee, false).raw.toNumber();
const warpFeeMessage = new TransactionMessage({
payerKey: payer.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: [
SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: this.warpFeeWallet,
lamports: fee,
}),
],
}).compileToV0Message();
try {
const fee = new CurrencyAmount(Currency.SOL, this.warpFee, false).raw.toNumber();
const warpFeeMessage = new TransactionMessage({
payerKey: payer.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: [
SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: this.warpFeeWallet,
lamports: fee,
}),
],
}).compileToV0Message();
const warpFeeTx = new VersionedTransaction(warpFeeMessage);
warpFeeTx.sign([payer]);
const warpFeeTx = new VersionedTransaction(warpFeeMessage);
warpFeeTx.sign([payer]);
const response = await axios.post<{ confirmed: boolean; signature: string; error?: string }>(
'https://tx.warp.id/transaction/execute',
{
transactions: [bs58.encode(warpFeeTx.serialize()), bs58.encode(transaction.serialize())],
latestBlockhash,
},
{
timeout: 100000,
},
);
const response = await axios.post<{ confirmed: boolean; signature: string; error?: string }>(
"https://tx.warp.id/transaction/execute",
{
transactions: [bs58.encode(warpFeeTx.serialize()), bs58.encode(transaction.serialize())],
latestBlockhash,
},
{
timeout: 100000,
},
);
return response.data;
} catch (error) {
if (error instanceof AxiosError) {
logger.trace({ error: error.response?.data }, 'Failed to execute warp transaction');
}
}
return response.data;
} catch (error) {
if (error instanceof AxiosError) {
logger.trace({ error: error.response?.data }, "Failed to execute warp transaction");
}
}
return { confirmed: false };
}
return { confirmed: false };
}
}