Skip to content

Instantly share code, notes, and snippets.

View rubpy's full-sized avatar
💭
💥 Phosphorylating

rubpy rubpy

💭
💥 Phosphorylating
View GitHub Profile
import web3 from "@solana/web3.js";
import * as BufferLayout from "@solana/buffer-layout";
//////////////////////////////////////////////////
export class BorshBoolean extends BufferLayout.Layout<boolean> {
constructor(property?: string) {
super(1, property);
}
// --- `@solana/web3.js` v1 ---
import web3 from '@solana/web3.js';
(async (rpcUrl: string) => {
const rpc = new web3.Connection(rpcUrl);
const subject = new web3.PublicKey('j1oAbxxiDUWvoHxEDhWE7THLjEkDQW2cSHYn2vttxTF');
const signatures = await rpc.getSignaturesForAddress(subject, {
limit: 1000,
}, 'finalized');
import type {
Commitment,
TransactionForAccounts,
TransactionForFullBase58,
TransactionForFullBase64,
TransactionForFullJsonParsed,
} from '@solana/rpc-types';
import type { TransactionVersion } from '@solana/transaction-messages';
import type { Address } from '@solana/addresses';
import type { Signature } from '@solana/keys';
import web3 from "@solana/web3.js";
import mmw from "@raydium-io/raydium-sdk";
import QuickLRU from "quick-lru";
//////////////////////////////////////////////////
export const OPAQUE_SIGNATURE = "1111111111111111111111111111111111111111111111111111111111111111";
export const SIGNATURE_PROGRAM = "Program ";
import web3 from "@solana/web3.js";
import * as BufferLayout from "@solana/buffer-layout";
import bs58 from "bs58";
//////////////////////////////////////////////////
class BorshString extends BufferLayout.Layout<string> {
constructor(property?: string) {
super(-1, property);
}
@rubpy
rubpy / TokenAccountMonitor.ts
Created July 17, 2024 01:00
Crude example of a gRPC/WebSocket-based Solana token price monitor.
import * as web3 from "@solana/web3.js";
import * as spl from "@solana/spl-token";
import bs58 from "bs58";
import GeyserClient, {
SubscribeRequest as GeyserSubscribeRequest,
SubscribeUpdate as GeyserSubscribeUpdate,
CommitmentLevel as GeyserCommitmentLevel,
} from "@triton-one/yellowstone-grpc";
import { ClientDuplexStream } from "@grpc/grpc-js";
@rubpy
rubpy / rpc_fetch_pump_global_state.ts
Created June 22, 2024 19:35
Tracking changes in Pump.fun global state (initialVirtualTokenReserves, initialVirtualSolReserves, initialRealTokenReserves, tokenTotalSupply, feeBasisPoints).
import * as web3 from "@solana/web3.js";
import bs58 from "bs58";
//////////////////////////////////////////////////
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 / 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 {
@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 / 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 },