Skip to content

piotrostr/listen

Repository files navigation

listen

Listen to new large transactions on Raydium V4

Swap using Jupiter V6 API or directly with Raydium (crucial for new listings)

Be careful as the default usage was on mainnet with small txs, be sure to set the URLs and signer keypair to testnet

Requirements

  1. Install Rust
  2. Install protoc, build-essential, pkg-config, libssl-dev
  3. Copy over .env.example into .env, plug your RPCs (otherwise uses solana default public RPCs)
  4. Copy over auth.json - JITO authentication keypair and fund.json - the keypair with some SOL to fund the endeavour
  5. Enable Rust Nightly and cargo build --release
  6. Run the ./run-systemd-services.sh to run the microservices

Usage

Listening on new swaps

Requires env var of RPC_URL with some quota, set the size of buffer for new transactions and the worker count that process incoming transactions

Listening is over wss://api.mainnet-beta.solana.com/, fetching transactions uses the url set in RPC_URL

cargo run -- listen \
  --worker-count [COUNT] \
  --buffer-size [SIZE]

Should yield output as

Metrics server running on 3030

Connecting to logs for 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8

Connecting to blocks through [RPC_URL]
Latest blockhash: BS8s86pQf45V9skwmzWz4GsYyZs6A8gsNWy4i9piV786
Signer: DmFqB5LdQspumdvtHRi4PHKTZENHMw2xRMmSXP6aSkfj

https://solana.fm/tx/3Gvmx...: 10.730849095 SOL
https://solana.fm/tx/4aGoJ...: 77.293938152 SOL
https://solana.fm/tx/j7TD...: 77.681362228 SOL

Automatically, it will send metrics to localhost:3030/metrics; to see the transactions received and processed in Prometheus, run

prometheus --config=prometheus.yml

This will start a server on localhost:3030/metrics that contains metrics (transactions_received and transactions_processed)

In Grafana it looks like this: image

Swapping

The account used to sign the transaction is by default the ~/.config/solana/id.json, but it is possible to specify the path using --keypair-path [PATH], the account has to be generated or imported using solana-keygen executable that ships with remaining the Solana SDK

Slippage can also be adjusted using --slippage [BPS], e.g. --slippage 50 for 0.5% slippage, default is 50, dynamic slippage and retries is in the prod roadmap

cargo run -- swap \
  --input-mint sol \
  --output-mint EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v \
  --amount 10000000

Amount is in lamports (or SPL-Token decimals), leave blank to automatically swap the entire balance of the input mint

There is an optional parameter -y or --yes which skips the confirmation on the user side

Swap profiling

There is a utility for profiling a single swap using DTrace and stackcollapse.pl (Repository), replace your home directory (mine is /Users/piotrostr) to point to the right id.json keypair

./hack/profile-swap.sh

The stackcollapse.pl can be installed through

gh repo clone brendangregg/FlameGraph && \
  sudo cp FlameGraph/stackcollapse.pl /usr/local/bin && \
  sudo cp FlameGraph/flamegraph.pl /usr/local/bin

yielding

image

About

listening on DeFi data

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published