Skip to content

x402agent/SolanaOS / skills/qedgen

qedgen

Flagged

Formally verify programs by writing Lean 4 proofs. Trigger this skill whenever the user wants to formally verify code, generate Lean 4 proofs, prove properties about algorithms or smart contracts, verify invariants, convert program logic into formal specifications, or anything involving Lean 4 and formal verification. Also trigger when the user mentions "qedgen", "lean proof", "formal proof", "verify my code", "prove correctness", "formal verification", or wants mathematical guarantees about their implementation.

FileKindSize
Cargo.lockmanifest38.2 KB
Cargo.tomlmanifest347 B
LICENSEother1.0 KB
README.mdmarkdown4.1 KB
SKILL.mdskill md21.0 KB
claude.mdmarkdown9.7 KB
crates/qedgen/Cargo.tomlmanifest544 B
crates/qedgen/src/api.rsscript38.9 KB
crates/qedgen/src/asm2lean.rsscript26.2 KB
crates/qedgen/src/consolidate.rsscript6.2 KB
crates/qedgen/src/main.rsscript4.7 KB
crates/qedgen/src/project.rsscript3.0 KB
crates/qedgen/src/spec.rsscript19.4 KB
crates/qedgen/src/validate.rsscript5.6 KB
crates/qedgen/templates/Main.leanother154 B
crates/qedgen/templates/PROMPT_TEMPLATE.mdmarkdown3.2 KB
crates/qedgen/templates/README.lean.mdmarkdown1.6 KB
crates/qedgen/templates/lakefile.leanother292 B
crates/qedgen/templates/lean-toolchainother25 B
docs/CNAMEother10 B
docs/index.htmlother11.6 KB
docs/llms-full.txtmarkdown8.7 KB
docs/llms.txtmarkdown2.1 KB
docs/logo-dark.svgother648 B
docs/logo-light.svgother648 B
docs/qgn_demo.htmlother69.3 KB
docs/style.cssother8.1 KB
examples/rust/escrow/Anchor.tomlconfig353 B
examples/rust/escrow/Cargo.lockmanifest72.8 KB
examples/rust/escrow/Cargo.tomlmanifest215 B
examples/rust/escrow/migrations/deploy.tsscript428 B
examples/rust/escrow/package.jsonmanifest528 B
examples/rust/escrow/programs/escrow/Cargo.tomlmanifest376 B
examples/rust/escrow/programs/escrow/Xargo.tomlconfig62 B
examples/rust/escrow/programs/escrow/src/lib.rsscript6.7 KB
examples/rust/escrow/tests/escrow.tsscript8.6 KB
examples/rust/escrow/tsconfig.jsonconfig205 B
examples/rust/percolator/Cargo.lockmanifest8.5 KB
examples/rust/percolator/Cargo.tomlmanifest639 B
examples/rust/percolator/LICENSEother11.1 KB
examples/rust/percolator/README.mdmarkdown4.9 KB
examples/rust/percolator/examples/offsets.rsscript1.3 KB
examples/rust/percolator/scripts/audit-proof-strength.mdmarkdown6.4 KB
examples/rust/percolator/scripts/proof-strength-audit-results.mdmarkdown89.2 KB
examples/rust/percolator/scripts/run_kani_full_audit.shexecutablescript1.2 KB
examples/rust/percolator/spec.mdmarkdown108.4 KB
examples/rust/percolator/src/i128.rsscript20.4 KB
examples/rust/percolator/src/percolator.rsscript139.3 KB
examples/rust/percolator/src/wide_math.rsscript59.8 KB
examples/rust/percolator/tests/amm_tests.rsscript7.4 KB
examples/rust/percolator/tests/common/mod.rsscript4.7 KB
examples/rust/percolator/tests/fuzzing.proptest-regressionsother4.7 KB
examples/rust/percolator/tests/fuzzing.rsscript43.1 KB
examples/rust/percolator/tests/proofs_arithmetic.rsscript17.1 KB
examples/rust/percolator/tests/proofs_audit.rsscript35.0 KB
examples/rust/percolator/tests/proofs_instructions.rsscript64.8 KB
examples/rust/percolator/tests/proofs_invariants.rsscript21.0 KB
examples/rust/percolator/tests/proofs_lazy_ak.rsscript22.4 KB
examples/rust/percolator/tests/proofs_liveness.rsscript17.1 KB
examples/rust/percolator/tests/proofs_safety.rsscript104.2 KB
examples/rust/percolator/tests/proofs_v1131.rsscript25.4 KB
examples/rust/percolator/tests/unit_tests.rsscript93.8 KB
examples/sbpf/counter/src/counter.sother22.9 KB
examples/sbpf/slippage/src/asm-slippage/asm-slippage.sother698 B
examples/sbpf/transfer/src/transfer.sother2.4 KB
examples/sbpf/tree/src/tree.sother61.1 KB
install.shexecutablescript5.5 KB
lean_solana/QEDGen.leanother165 B
lean_solana/QEDGen/Solana.leanother165 B
lean_solana/QEDGen/Solana/Account.leanother4.0 KB
lean_solana/QEDGen/Solana/Authority.leanother285 B
lean_solana/QEDGen/Solana/Cpi.leanother9.0 KB
lean_solana/QEDGen/Solana/SBPF.leanother130 B
lean_solana/QEDGen/Solana/SBPF/Execute.leanother12.2 KB
lean_solana/QEDGen/Solana/SBPF/ISA.leanother5.1 KB
lean_solana/QEDGen/Solana/SBPF/Memory.leanother6.1 KB
lean_solana/QEDGen/Solana/SBPF/Tactic.leanother2.3 KB
lean_solana/QEDGen/Solana/State.leanother1.9 KB
lean_solana/QEDGen/Solana/Valid.leanother2.0 KB
lean_solana/README.mdmarkdown2.5 KB
lean_solana/lake-manifest.jsonconfig119 B
lean_solana/lakefile.leanother112 B
lean_solana/lean-toolchainother25 B
lean_solana/test_lemmas.leanother2.3 KB
package.jsonmanifest762 B
tools/qedgenexecutablescript357 B

examples/rust/percolator/tests/amm_tests.rs

View on GitHub
// End-to-end integration tests with realistic trading scenarios
// Tests complete user journeys with multiple participants

#[cfg(feature = "test")]
use percolator::*;
#[cfg(feature = "test")]
use percolator::i128::U128;

#[cfg(feature = "test")]
fn default_params() -> RiskParams {
    RiskParams {
        warmup_period_slots: 100,
        maintenance_margin_bps: 500, // 5%
        initial_margin_bps: 1000,    // 10%
        trading_fee_bps: 10,         // 0.1%
        max_accounts: 64,
        new_account_fee: U128::new(0),
        maintenance_fee_per_slot: U128::new(0),
        max_crank_staleness_slots: u64::MAX,
        liquidation_fee_bps: 50,
        liquidation_fee_cap: U128::new(100_000),
        liquidation_buffer_bps: 100,
        min_liquidation_abs: U128::new(0),
        min_initial_deposit: U128::new(2),
        min_nonzero_mm_req: 1,
        min_nonzero_im_req: 2,
        insurance_floor: U128::ZERO,
    }
}

/// Helper: create i128 position size from base quantity (scaled by POS_SCALE)
#[cfg(feature = "test")]
fn pos_q(qty: i64) -> i128 {
    let abs_val = (qty as i128).unsigned_abs();
    let scaled = abs_val.checked_mul(POS_SCALE).unwrap();
    if qty < 0 {
        -(scaled as i128)
    } else {
        scaled as i128
    }
}

/// Helper: crank to make trades/withdrawals work
#[cfg(feature = "test")]
fn crank(engine: &mut RiskEngine, slot: u64, oracle_price: u64) {
    let _ = engine.keeper_crank(slot, oracle_price, &[], 64);
}

// ============================================================================
// E2E Test 1: Complete User Journey
// ============================================================================

#[test]
#[cfg(feature = "test")]
fn test_e2e_complete_user_journey() {
    // Scenario: Alice and Bob trade, experience PNL, warmup, withdrawal

    let mut engine = Box::new(RiskEngine::new(default_params()));

    // Initialize insurance fund
    let _ = engine.top_up_insurance_fund(50_000, 0);

    // Add two users with capital
    let alice = engine.add_user(0).unwrap();
    let bob = engine.add_user(0).unwrap();

    let oracle_price: u64 = 100; // 100 quote per base

    // Users deposit principal
    engine.deposit(alice, 100_000, oracle_price, 0).unwrap();
    engine.deposit(bob, 150_000, oracle_price, 0).unwrap();

    // Make crank fresh
    crank(&mut engine, 0, oracle_price);

    // === Phase 1: Trading ===

    // Alice goes long 50 base, Bob takes the other side (short)
    engine
        .execute_trade(alice, bob, oracle_price, 0, pos_q(50), oracle_price)
        .unwrap();

    // Check effective positions
    let alice_eff = engine.effective_pos_q(alice as usize);
    let bob_eff = engine.effective_pos_q(bob as usize);
    assert!(alice_eff > 0, "Alice should be long");
    assert!(bob_eff < 0, "Bob should be short");

    // Conservation should hold
    assert!(engine.check_conservation(), "Conservation after trade");

    // === Phase 2: Price Movement ===

    let new_price: u64 = 120; // +20%

    // Accrue market to new price
    engine.advance_slot(10);
    let slot = engine.current_slot;
    engine.accrue_market_to(slot, new_price).unwrap();

    // Settle side effects for Alice (should have positive PnL from long)
    engine.settle_side_effects(alice as usize).unwrap();

    let alice_pnl = engine.accounts[alice as usize].pnl;
    // Long position + price up = positive PnL
    assert!(alice_pnl > 0, "Alice should have positive PnL after price increase");

    // === Phase 3: PNL Warmup ===

    // Advance some slots
    engine.advance_slot(50);

    // Touch to settle and convert warmup
    let slot = engine.current_slot;
    engine.touch_account_full(alice as usize, new_price, slot).unwrap();

    // The key invariant is conservation
    assert!(engine.check_conservation(), "Conservation after warmup");

    // === Phase 4: Close positions and withdraw ===

    let slot = engine.current_slot;
    crank(&mut engine, slot, new_price);

    // Alice closes her position (sell)
    let alice_pos = engine.effective_pos_q(alice as usize);
    if alice_pos != 0 {
        let neg_pos = alice_pos.checked_neg().unwrap();
        let slot = engine.current_slot;
        engine
            .execute_trade(alice, bob, new_price, slot, neg_pos, new_price)
            .unwrap();
    }

    // Advance for full warmup
    engine.advance_slot(200);
    let slot = engine.current_slot;
    engine.touch_account_full(alice as usize, new_price, slot).unwrap();

    // Alice withdraws some capital
    let slot = engine.current_slot;
    crank(&mut engine, slot, new_price);
    let alice_cap = engine.accounts[alice as usize].capital.get();
    if alice_cap > 1000 {
        let slot = engine.current_slot;
        engine.withdraw(alice, 1000, new_price, slot).unwrap();
    }

    assert!(engine.check_conservation(), "Conservation after withdrawal");
}

// ============================================================================
// E2E Test 2: Funding Complete Cycle
// ============================================================================

#[test]
#[cfg(feature = "test")]
fn test_e2e_funding_complete_cycle() {
    // Scenario: Users trade, funding accrues over time, positions flip

    let mut engine = Box::new(RiskEngine::new(default_params()));
    let _ = engine.top_up_insurance_fund(50_000, 0);

    let alice = engine.add_user(0).unwrap();
    let bob = engine.add_user(0).unwrap();

    let oracle_price: u64 = 100;

    engine.deposit(alice, 200_000, oracle_price, 0).unwrap();
    engine.deposit(bob, 200_000, oracle_price, 0).unwrap();

    crank(&mut engine, 0, oracle_price);

    // Alice goes long, Bob goes short
    engine
        .execute_trade(alice, bob, oracle_price, 0, pos_q(100), oracle_price)
        .unwrap();

    // Advance time and accrue funding with a positive rate (longs pay shorts)
    engine.advance_slot(20);

    // Run keeper_crank to advance
    let slot = engine.current_slot;
    let _ = engine.keeper_crank(slot, oracle_price, &[], 64);

    // Advance more time for funding to accrue
    engine.advance_slot(20);

    // Accrue market with funding
    let slot = engine.current_slot;
    engine.accrue_market_to(slot, oracle_price).unwrap();

    // Settle effects for both
    engine.settle_side_effects(alice as usize).unwrap();
    engine.settle_side_effects(bob as usize).unwrap();

    let _alice_pnl = engine.accounts[alice as usize].pnl;
    let _bob_pnl = engine.accounts[bob as usize].pnl;

    // Alice (long) paid funding, so negative PnL
    // Bob (short) received funding, so positive PnL
    // (With 50 bps/slot rate * 20 slots, the K coefficients should reflect this)
    // The exact values depend on the A/K mechanism, but the sign should be correct:
    // funding_rate > 0 means longs pay -> K_long decreases, K_short increases

    // Conservation should still hold
    assert!(engine.check_conservation(), "Conservation after funding");

    // === Positions Flip ===

    let slot = engine.current_slot;
    crank(&mut engine, slot, oracle_price);

    // Alice closes long and opens short (total -200 base)
    engine
        .execute_trade(alice, bob, oracle_price, slot, pos_q(-200), oracle_price)
        .unwrap();

    // Now Alice is short and Bob is long
    let alice_eff = engine.effective_pos_q(alice as usize);
    let bob_eff = engine.effective_pos_q(bob as usize);
    assert!(alice_eff < 0, "Alice should now be short");
    assert!(bob_eff > 0, "Bob should now be long");

    assert!(engine.check_conservation(), "Conservation after position flip");
}
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall