Use casesHow it worksDocsLaunch app

Documentation

Borrow, use, repay

Everything you need to put a Wedesak flash loan inside your own Solana transaction, and to test it before it touches mainnet.

Overview

A flash loan is liquidity you hold for exactly one transaction. Wedesak lends from per-asset vaults; the only condition is that the same transaction returns principal plus a 1 bp fee before it ends. If it does not, the transaction reverts and the loan never existed.

There is no callback: a program cannot be re-entered mid-chain and cross-program invocation depth is capped at 4. So the loan is two top-level instructions — borrow first, repay last — and the borrow checks the repay exists by reading the Instructions sysvar before it moves funds.

Instructions

borrow

Moves amount from the reserve vault to the borrower’s token account. Before transferring it walks the Instructions sysvar forward from its own index and requires exactly one later repay for the same vault, mint and borrower. Rejected when called through CPI (stack height above 1).

AccountSignerWritableNotes
reserve—yesPer-asset state: liquidity, fee, frozen flag
vault—yesToken account owned by the reserve PDA
borroweryes—Any wallet or program-derived signer
borrower_token—yesDestination for the loan
instructions——Sysvar1nstructions1111111111111111111111111
token_program——SPL Token or Token-2022

repay

Transfers principal plus fee back to the vault. The amount is read from the matching borrow, so you never pass it twice. The fee accrues to the reserve’s depositors.

let ixs = vec![
    wedesak::ix::borrow(reserve, borrower, amount),
    // … your instructions …
    wedesak::ix::repay(reserve, borrower),
];

Error codes

CodeNameMeaning
6000MissingRepayNo repay instruction for this vault later in the transaction.
6001RepayAmountMismatchRepay transfers less than principal + fee.
6002BorrowViaCpiBorrow was invoked from another program; it must be a top-level instruction.
6003MultipleBorrowsMore than 1 borrow in the same transaction.
6004RepayAccountMismatchRepay names a different vault, mint or borrower than the borrow.
6005InsufficientLiquidityThe reserve cannot cover the requested amount.
6006ReserveFrozenBorrowing from this reserve is paused by governance.

TypeScript SDK

The SDK builds the instruction pair around whatever you pass in, sets a compute units limit with 10% headroom and, when a lookup table is supplied, compiles a v0 message.

npm i @wedesak-protocol/sdk

import { Wedesak } from "@wedesak-protocol/sdk";

const fl = new Wedesak(connection);
const tx = await fl.wrap({
  borrow: { mint: USDC_MINT, amount: 25_000_000_000n },
  instructions: [liquidateIx, swapIx],
  lookupTables: [routeAlt],
  priorityMicroLamports: 1_000,
});

Rust test kit

wedesak-kit runs your program and the loan in-process on a local runtime, so a full borrow → route → repay test finishes in milliseconds. It wraps the common cheatcodes so tests read like the scenario they check.

CheatcodeWhat it does
warp_to_slot(n) / warp_to_timestamp(t)Move the Clock sysvar to test expiry, interest accrual and oracle staleness.
deal(account, mint, amount)Give any address SOL or SPL tokens without a faucet.
set_account(pubkey, data)Seed or overwrite any account — a pool at a given price, a position at a given health.
prank(signer) / stop_prank()Send the next instructions as another key to test permission checks.
expect_revert(err)Assert the exact error and that no account changed.
#[test]
fn liquidation_repays() {
    let mut kit = wedesak_kit::Kit::new()
        .with_program(MY_PROGRAM_ID, "target/deploy/my_program.so")
        .deal(&bot, USDC, 50_000)
        .set_account(&position, unhealthy_position());

    let res = kit.send(&[borrow(USDC, 18_400), liquidate(&position), swap(SOL, USDC), repay(USDC)]);
    assert!(res.is_ok());
    assert!(kit.balance(&bot, USDC) > 50_000);
}

The kit does not fork mainnet state. Seed the accounts your route touches with set_account, or snapshot them from an RPC once and commit the fixtures.

Transaction limits

  • 1,400,000 compute units per transaction; 200,000 per instruction unless you request more. The priority fee is charged on the limit you request, not what you use.
  • 1,232 bytes per legacy or v0 transaction. Multi-hop routes need an address lookup table; a newly extended table is usable from the next slot.
  • 64 account locks per transaction.
  • Cross-program invocation depth 4, which is why borrow and repay stay top-level.

The composer budgets all of these live while you build a route.

Fees

1 bp of principal on every repaid loan, paid in the borrowed asset, 100% to the reserve’s depositors. Reverted transactions pay nothing to the protocol — only the network’s own transaction fee. See the comparison with other venues.