Skip to content

Instantly share code, notes, and snippets.

View totdking's full-sized avatar
🏠
Working from home

Konquest totdking

🏠
Working from home
View GitHub Profile
@totdking
totdking / revised_findings.md
Last active September 26, 2025 10:13
list of audit vuln gotten for solana wager audit comp

1. Wrong payment logic in distribute_winnings.rs

Summary

The distribution logic lacks the check to properly differenctiate between a pay to spawn and the winner takes all game variant

Description

The distribute_pay_spawn_earnings() and the distribute_all_winnings_handler intended design is to distribute rewards based on the game mode participated in by the user. But there are no way to tell the contract which is which, all it does is simply distribute rewards to accounts without specifying what type of rewards it is supposed to be.

Likelihood

The likelihood is incredibly high as all it needs is to deliver the wrong payload of ix to a user from the w

@totdking
totdking / settings.json
Last active September 4, 2025 20:18
to make a ts code variable type visible and js
// OPEN CTRL+SHIFT+P
// type in open settings and go to open user settings json
// paste this there
{
// Shows the inferred type for variables. This is the main one you want.
"typescript.inlayHints.variableTypes.enabled": "all",
// Shows the inferred return type for functions. Super helpful in tests.
"typescript.inlayHints.functionLikeReturnTypes.enabled": "all",
@totdking
totdking / main.rs
Created May 27, 2025 17:46
newton Raphson implementation in rust
fn main() {
//EXAMPLE OF USING THE NEWTON RAPHSON
let x = 1_000_000.0; // e.g., USDC
let y = 1_000_000.0; // e.g., USDT
let amp = 100.0; // Amplification coefficient
let d = compute_invariant(x, y, amp);
println!("Invariant D: {:.10}", d);
// simulate adding 1000 to x and calculating new y
fn main() {
let mut arr1 = [5,2,6, 12,234,68, -21, -600];
println!("{:?}", bubble_sort(&mut arr1));
}
pub fn bubble_sort<T: Ord + Clone>(arr: &mut [T])-> Vec<T>{
if arr.is_empty(){
return Vec::new();
}
for i in 0.. arr.iter().count(){
for j in 0..arr.len() - i -1{
use core::panic;
use std::io::ErrorKind;
pub use std::fs::File;
fn main() {
// let file = File::open(
// "/home/konquest/home/konquest/rust/Rust-for-practice/floating_point/src/hello.md",
// );
let file = File::open("hello.js");
@totdking
totdking / fee_calc.rs
Created April 1, 2025 07:25
This is for calculating fees in a bonding curve(pump swap)
use crate::common::PumpAmmError;
use anchor_lang::error;
use anchor_spl::token_2022::spl_token_2022::extension::transfer_fee::MAX_FEE_BASIS_POINTS;
pub fn ceil_div(numerator: u128, denominator: u128) -> anchor_lang::Result<u128> {
numerator
.checked_add(denominator)
.ok_or_else(|| error!(PumpAmmError::Overflow))?
.checked_sub(1)
.ok_or_else(|| error!(PumpAmmError::Overflow))?
// TO FIND A MATCHING NAME IN AN ARRAY FROM A STRUCT
fn main(){
get_quantity("Apple");
}
struct GrocItem{
name: String,
// price: f64,
quantity: u32,
}
fn get_quantity(item_name: &str)->Option<u32>{
@totdking
totdking / main.rs
Last active January 19, 2025 13:28
This was for a mini project to take in user data and add to a storage array.
use std::io::{self,Write};
// TO USE THE .flush().unwrap() TO IMMEDIATELY DISPLAY THE PRINTLN MACRO AND USING .MAP_ERR TO PROPERLY HANDLE ERROR WITH THE "?"
//THIS IS FOR RETURNING A RESULT TYPE
// HAD TO USE LOOP/MATCH TO HANDLE ERROR SO THE PROGRAM WON'T PANIC AFTER ENCOUNTERING AN ERROR
let mut age = String::new();
println!("Input your age");
io::stdout().flush().unwrap();
io::stdin().read_line(&mut age).map_err(|e|format!("Could not read age: {}", e))?;
let person_age: u32 = age.trim().parse().expect("Pls input a valid number");
@totdking
totdking / fundauthority.ts
Last active March 15, 2025 23:35
Typescript code to fund the authority keypair incase error of inadequate lamports occus
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { PdaProgram } from "../target/types/pda_program";
import {Connection, Transaction, SystemProgram, PublicKey} from "@solana/web3.js";
import { BN } from "bn.js";
describe("pda_program", () => {
// Configure the client to use the local cluster.
let provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
use anchor_lang::prelude::*;
// use anchor_spl::token::{Mint,TokenAccount};
declare_id!("B79TnXm2vponTSgXgnDLe5R1hPthTwwApFq2uGBQgV9r");
#[program]
pub mod pda_program {
use super::*;
pub fn initialize(ctx: Context<InitializePda>, amount : u64) -> Result<()> {