Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark trade streams #75

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
rename
  • Loading branch information
tinystarinagalaxy committed Jan 16, 2024
commit 97f145a38e01f7893825f02c891c30f386258e51
26 changes: 15 additions & 11 deletions examples/benchmark_submit_tx_helius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
import { randomInt } from "crypto"

const httpHeaders = { }
const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=88e7c870-b0e3-4a59-b80f-8d78f01e5e4a',
const endpoint = 'https://proud-fabled-crater.solana-mainnet.quiknode.pro/e3bfb432b5b982fb3e296b8fd1ec3a2d91124d76/'
// const endpoint = 'https://mainnet.competitor-rpc.com/?api-key=88e7c870-b0e3-4a59-b80f-8d78f01e5e4a'
const connection = new Connection(
endpoint,
{httpHeaders});

const config = loadFromEnv()
Expand All @@ -35,11 +38,11 @@ type RequestPair = {
hSignature: string;
};
let blx_win = 0;
let helius_win = 0;
let competitor_win = 0;
let equal = 0;
let total_diff = 0;
const noOfComparisons = 100;
const dataArray: { diff: number; trader_api_slot: number; helius_slot: number; tSignature: string, hSignature: string}[] = [];
const dataArray: { diff: number; trader_api_slot: number; competitor_slot: number; tSignature: string, hSignature: string}[] = [];
console.log("connecting to trader api")
await provider.connect()
console.log("connected to trader api")
Expand All @@ -65,7 +68,7 @@ async function submitTx() {
const requestPairs: RequestPair[] = []
const BONK = "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263"
for (let i = 1; i <= noOfComparisons; i++) {
const resHelius = await provider.postTradeSwap({
const rescompetitor = await provider.postTradeSwap({
ownerAddress: config.publicKey,
inToken: BONK,
outToken: "USDC",
Expand All @@ -89,7 +92,7 @@ async function submitTx() {
));


const serializedTransactions = resHelius.transactions.map((tx) => signTxMessage(
const serializedTransactions = rescompetitor.transactions.map((tx) => signTxMessage(
tx,
privateKey,
));
Expand Down Expand Up @@ -125,15 +128,15 @@ async function submitTx() {
hSignature: "",
};
requestPairs.push(newPair);
console.log("submitted tx to trader api and helius : " + i)
console.log("submitted tx to trader api and competitor : " + i)
} // for loop
const allResults = []
const wait = 60000
console.log("sleeping for ", wait , " millis ")
await sleep(wait);
let tSignature
for (const requestPair of requestPairs) {
console.log("waiting for tx from helius")
console.log("waiting for tx from competitor")
let hSignature = ""
for (let i = 0; i < 10; i++) {
try {
Expand Down Expand Up @@ -206,7 +209,7 @@ async function submitTx() {
if (res.tBlockNumber < res.hBlockNumber) {
blx_win++
} else if (res.tBlockNumber > res.hBlockNumber) {
helius_win++
competitor_win++
} else {
equal++
}
Expand All @@ -216,7 +219,7 @@ async function submitTx() {
dataArray.push({
diff : res.tBlockNumber - res.hBlockNumber,
trader_api_slot: res.tBlockNumber,
helius_slot: res.hBlockNumber,
competitor_slot: res.hBlockNumber,
tSignature: res.tSignature,
hSignature: res.hSignature,
})
Expand Down Expand Up @@ -252,10 +255,11 @@ async function getBlockNumber(signature: string) {

await submitTx()
console.table(dataArray);
console.log("endpoint : " + endpoint)
console.log("blx_win : " + blx_win)
console.log("blx_win % : " + blx_win * 100 / noOfComparisons)
console.log("helius_win : " + helius_win)
console.log("helius_win % : " + helius_win * 100 / noOfComparisons)
console.log("competitor_win : " + competitor_win)
console.log("competitor_win % : " + competitor_win * 100 / noOfComparisons)
console.log("equal : " + equal)
console.log("equal % : " + equal * 100 / noOfComparisons)
console.log("total_diff on avg(block distance): " + total_diff / noOfComparisons)
Expand Down
Loading