Skip to content

Instantly share code, notes, and snippets.

View rubpy's full-sized avatar
💭
💥 Phosphorylating

rubpy rubpy

💭
💥 Phosphorylating
View GitHub Profile
@rubpy
rubpy / seg_display.ino
Created June 20, 2022 23:01
A (better-coded) example of a 0-to-9 counter running on an Arduino & displaying the digits on a 7-segment LED display
#include <stdint.h>
/**
* A (better-coded) example of a 0-to-9 counter running on
* an Arduino & displaying the digits on a 7-segment LED display.
*
* Based on: https://create.arduino.cc/projecthub/akhtar/simple-0-9-counter-dcba41
*
* Try it in a simulator: https://wokwi.com/projects/335025004843369044
*/
@rubpy
rubpy / derdec.h
Last active July 30, 2022 19:03
derdec.h - a silly single-header library for extracting modulus N & exponent E arbitrary-precision integers from ASN.1 DER-encoded RSA public keys
#ifndef DERDEC_H
#define DERDEC_H
// clang-format off
/****************************************************************************
*
* MIT License
*
* Copyright (c) 2022 by pr3 (https://discord.com/users/552136433742381066 👀)
@rubpy
rubpy / encrypt_with_bear.c
Last active July 29, 2022 20:53
encrypt_with_bear - a handy wrapper for the low-level BearSSL RSA encryption API
#include <bearssl.h>
#include <derdec.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
/* (RSA-2048)
-----BEGIN PUBLIC KEY-----
MIIBITANBgkqhkiG9w0BAQEFAAOCAQ4AMIIBCQKCAQBez9MX9NzGasT/wlMKgLPL
@rubpy
rubpy / Makefile
Created January 16, 2023 18:18
A quick Makefile! 🧩
# ===== Directory structure =====
# build/
# foo/
# another.c.o
# main
# main.c.o
# other.c.o
#
# lib/
#
@rubpy
rubpy / raydium_sdk_v2_example.ts
Created June 6, 2024 00:43
Fetching pool info and determining prices of token/SOL & SOL/USDC pairs via Raydium SDK V2.
import * as raydium from "@raydium-io/raydium-sdk-v2";
//////////////////////////////////////////////////
const RAYDIUM_CLMM_SOL_USDC_ID = "2QdhepnKRTLjjSqPL1PtKNwqrUkoLee5Gqs8bvZhRdMv";
function normalizeRaydiumBetaPoolInfoResponse(response: raydium.ApiV3PoolInfoItem[] | raydium.ApiV3PageIns<raydium.ApiV3PoolInfoItem>): raydium.ApiV3PoolInfoItem[] {
if (response === null || typeof response !== "object") {
return [];
}
@rubpy
rubpy / rpc_fetch_raydium_pool_init.ts
Created June 6, 2024 19:40
Finds Raydium AMM pool initialization transaction (partially deserializes pool state, calls getSignaturesForAddress, searches for a Raydium innerInstruction, etc.).
import * as web3 from "@solana/web3.js";
import bs58 from "bs58";
//////////////////////////////////////////////////
function findInstructionsInTransaction(
tx: web3.ParsedTransactionWithMeta,
predicate?: (instruction: web3.ParsedInstruction | web3.PartiallyDecodedInstruction, outerInstruction: (web3.ParsedInstruction | web3.PartiallyDecodedInstruction) | null) => boolean,
): Array<web3.ParsedInstruction | web3.PartiallyDecodedInstruction> {
if (!tx || !tx.meta || !tx.transaction || !tx.transaction.message || !tx.transaction.message.instructions) {
@rubpy
rubpy / rpc_fetch_pump_token_price.ts
Created June 20, 2024 18:39
Fetching Pump.fun bonding curve state and calculating price of token/SOL.
import * as web3 from "@solana/web3.js";
//////////////////////////////////////////////////
function readBytes(buf: Buffer, offset: number, length: number): Buffer {
const end = offset + length;
if (buf.byteLength < end) throw new RangeError("range out of bounds");
return buf.subarray(offset, end);
}
@rubpy
rubpy / pump_idl.json
Created June 20, 2024 19:52
Pump.fun program IDL (v0.1.0)
{
"version": "0.1.0",
"name": "pump",
"instructions": [
{
"name": "initialize",
"docs": [ "Creates the global state." ],
"accounts": [
{ "name": "global" , "isMut": true , "isSigner": false },
{ "name": "user" , "isMut": true , "isSigner": true },
@rubpy
rubpy / rpc_fetch_metaplex_token_metadata.ts
Created June 20, 2024 20:46
Fetching on-chain Metaplex token metadata (through lightweight getAccountInfo).
import * as web3 from "@solana/web3.js";
import {
MPL_TOKEN_METADATA_PROGRAM_ID,
MetadataAccountData as MplMetadataAccountData,
getMetadataAccountDataSerializer,
} from "@metaplex-foundation/mpl-token-metadata";
//////////////////////////////////////////////////
const METAPLEX_PROGRAM_ID = new web3.PublicKey(MPL_TOKEN_METADATA_PROGRAM_ID);
@rubpy
rubpy / rpc_fetch_token_mint_info.ts
Created June 20, 2024 21:16
Fetching basic token (mint) info (through getAccountInfo), e.g.: total supply, mintAuthority, freezeAuthority...
import * as web3 from "@solana/web3.js";
import { TOKEN_PROGRAM_ID, unpackMint, Mint } from "@solana/spl-token";
//////////////////////////////////////////////////
async function getTokenInfo(conn: web3.Connection, tokenMint: web3.PublicKey): Promise<Mint | null> {
const info = await conn.getAccountInfo(tokenMint);
if (!info) return null;
try {