Skip to content

Instantly share code, notes, and snippets.

@wphan
wphan / auctionSubscriberExample.ts
Created March 20, 2024 06:52
Minimal AuctionSubscriber Example
import {
DriftClient,
AuctionSubscriber,
Wallet,
DRIFT_PROGRAM_ID,
} from '@drift-labs/sdk'
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
const main = async () => {
const connection = new Connection("ur own working rpc");
@wphan
wphan / event_subscriber_example.py
Last active February 23, 2024 10:21
driftpy EventSubscriber example
from solana.rpc.async_api import AsyncClient
from solders.keypair import Keypair
from anchorpy import Wallet
from driftpy.drift_client import DriftClient
from driftpy.account_subscription_config import AccountSubscriptionConfig
from driftpy.events.event_subscriber import EventSubscriber
from driftpy.events.types import WrappedEvent, EventSubscriptionOptions, WebsocketLogProviderConfig
import os
@wphan
wphan / convert_solana_private_key.py
Last active December 7, 2023 18:05
convert between common solana keypair formats
#!//usr/bin/python3
# python env needs base58 package
# this format is suitable for raycast script commands!
# https://github.com/raycast/script-commands
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Convert Solana Private Key
# @raycast.mode fullOutput
@wphan
wphan / solana_keypair.rs
Created December 7, 2023 17:43
Loading solana private keys in rust (supports common formatS)
use std::error::Error;
use anchor_client::{
anchor_lang::__private::base64,
solana_sdk::{bs58, signature::Keypair},
};
pub fn read_keypair_str_multi_format(data: String) -> Result<Keypair, Box<dyn Error>> {
// strip out any white spaces and new line/carriage return characters
let data = data.replace([' ', '\n', '\r'], "");
@wphan
wphan / parseDriftEventLogs.ts
Created May 31, 2023 03:50
Decode an anchor log from Drift V2 with Typescript SDK
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
import {
configs,
DriftClient,
Wallet,
} from "@drift-labs/sdk";
async function main() {
@wphan
wphan / minimumViableDLOB.ts
Last active March 27, 2024 11:36
Load Drift V2 DLOB with Typescript SDK
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
import {
BASE_PRECISION,
BulkAccountLoader,
configs,
convertToNumber,
DLOBSubscriber,
DriftClient,
getMarketsAndOraclesForSubscription,
MarketType,