Skip to content

Instantly share code, notes, and snippets.

@ochaloup
ochaloup / block_rewards_solana.sh
Last active December 4, 2024 15:04
Getting block rewards data from Solana ror an epoch
export RPC_URL=...
# --- Finding the list of blocks that were created in epoch
SLOTS_PER_EPOCH=432000
START_BLOCK=302400000
EPOCH=$(($START_BLOCK/$SLOTS_PER_EPOCH))
echo "Epoch: $EPOCH"
I=0
is_end=false
while ! $is_end; do
@ochaloup
ochaloup / flipside claimsettlement tx fee query.sql
Last active November 18, 2024 09:50
flipside spending tx fees query
-- block first/end: https://github.com/ochaloup/solana-list-epoch-boundaries
WITH claim_settlements AS (select
floor(block_id/432000) AS epoch,
sum(pre_balances[0])- sum(post_balances[0]) as spending,
from solana.core.fact_transactions,
LATERAL FLATTEN(input => instructions) ixs,
where 1=1
and ixs.value:programId = 'vBoNdEvzMrSai7is21XgVYik65mqtaKXuSdMBJ1xkW4'
-- tx fee payer is at the first account key index 0
and account_keys[0]:pubkey = 'BNFeevU8uB8xtMSVXMDddzLQvPdKoV82S8dSWVv1KQre'
@ochaloup
ochaloup / 01 get-discriminator.sh
Last active October 24, 2024 05:52
Marinade Liquid Stakng Program - Delayed Ticket
# gettting anchor discriminator (8 bytes at start of the Solana anchor generated account)
git clone https://github.com/marinade-finance/liquid-staking-program
cd liquid-staking-program
anchor expand
grep -e 'Discriminator.*TicketAccountData' -A 3 .anchor/expanded-macros/marinade-finance/marinade-finance-*
> impl anchor_lang::Discriminator for TicketAccountData {
> const DISCRIMINATOR: [u8; 8] = [133, 77, 18, 98, 211, 1, 231, 3];
@ochaloup
ochaloup / solana-bankrun-update.md
Created September 9, 2024 10:37
solana-bankrun code update
@ochaloup
ochaloup / RUST_OPTION_RESULT_CONVERSIONS.md
Created August 27, 2024 10:15 — forked from novafacing/RUST_OPTION_RESULT_CONVERSIONS.md
Rust Option/Result conversion functions

I used to have a site bookmarked with a table of all these functions, but the link is dead. Here's a matrix of Option and Result conversion functions. These become second nature once you have used Rust for any significant length of time, but it's useful to have a table reference.

For each of the below:

  • T is the value possibly contained in an input Ok Result or Some Option.
  • U is a new value created by transforming or replacing an input T. Note that when U appears in methods like map, U ?= T, for example by calling
@ochaloup
ochaloup / byte_bits.rs
Last active June 6, 2024 11:42
Shifting with bytes bits in Rust
fn main() {
let data: &mut [u8] = &mut [0, 0, 0, 0]; // your byte slice
let index: usize = 2; // the position where you want to write the byte
let byte: u8 = 42; // the byte you want to write; 42 =>
// Write the byte to the specified position in the byte slice
data[index] = byte;
print_byte(&byte);
@ochaloup
ochaloup / spl-pool-loader.sh
Last active June 6, 2024 07:40
Loading data about mint pubkey for the SPL Pool program
#!/bin/bash
# Using different scripts from the gist
# bintodec.sh
# - https://discord.com/channels/@me/1017776053873287258/1247924569319149649
# arraybyindex.sh
# - https://gist.github.com/ochaloup/4d6ca93a6826a65c3f1f781d5af59d4b
# tobase58.py
# - https://discord.com/channels/@me/1017776053873287258/1247924569319149649
@ochaloup
ochaloup / bintodec.sh
Last active June 5, 2024 14:56
Binary format to decimal bytes format
if [ "$1" == "-h" ] || [ $# -eq 0 ] || [ $# -gt 1 ]; then
echo "Expecting one parameter, a path to binary file, e.g. 'solana -um account -o /tmp/data.bin'"
echo "$0 /tmp/data.bin"
exit 0
fi
FILE="$1"
decimal_array=($(od -v -An -t u1 < "$FILE"))
echo -n '['$(echo -n ${decimal_array[@]} | sed 's/ /,/g')']'
@ochaloup
ochaloup / buildkite-test.yml
Created April 28, 2024 06:05
Buildkite script managing upload artifacts and failures
agents:
queue: "snapshots"
steps:
- label: ":mega: Notification setup"
commands:
- 'notification_color="8388863"'
- 'buildkite-agent meta-data set notification_color "$$notification_color"'
- |
epoch=333
echo "$$DISCORD_WEBHOOK_VALIDATOR_BONDS" -H "Content-Type: application/json" -d '{
@ochaloup
ochaloup / #search_solana_vote_and_stake_account
Last active September 1, 2024 15:36
Solana search for VoteAccount - by validator identity (node_pubkey) and StakeAcccount - by staker/withdrawer/voter
Changing name:
https://stackoverflow.com/questions/19896900/how-to-change-the-name-of-a-gist-in-github/62398008#62398008