whitenois3
flashloan-rs
Rust

Minimal flashloan borrower contracts with an extensible rust sdk to abstract wrapping generic onchain calls (similar to multicall3) with flashloans.

Last updated Jun 26, 2026
91
Stars
12
Forks
0
Issues
0
Stars/day
Attention Score
16
Language breakdown
Rust 51.8%
Solidity 48.2%
โ–ธ Files click to expand
README

flashloan-rs โ€ข ci license solidity Crates.io

Minimal flashloan borrower contracts with an extensible rust sdk.

Getting Started

Flashloan-rs is published to crates.io as flashloan-rs.

To use the crate in a Rust project, run the cargo add command like so: cargo add flashloan-rs.

Or, add the following to your Cargo.toml:

[dependencies]
flashloan-rs = "0.2.3"

Usage

Flashloan-rs is built to be extremely simple to use.

Quick Construction

,ignore
use std::{str::FromStr, sync::Arc};
use flashloan_rs::prelude::*;
use ethers::prelude::*;

// Create a web3 provider let client = Provider::<Http>::try_from("https://eth-mainnet.g.alchemy.com/v2/your-api-key").unwrap(); let arc_client = Arc::new(client);

// Config let walletaddress = Address::fromstr("YOUR_ADDRESS").unwrap(); let lender = Address::fromstr("LENDERADDRESS").unwrap(); let tokentoflashloan = Address::fromstr("TOKENADDRESSTOFLASHLOAN").unwrap(); let amounttoflashloan = U256::fromdecstr("1000000000000000000").unwrap();

// Create a flashloan builder // Alternatively, these parameters can be set using the builder pattern (see the next example) let mut builder = FlashloanBuilder::new( Arc::clone(&arc_client), // web3 provider 1, // chain id Some(wallet_address), // wallet public address Some(lender), // address of the EIP-3156 Compliant Flash Lender Some(tokentoflashloan), // token address to flashloan Some(amounttoflashloan), // amount to flashloan None, // override the flash borrower contract );

// Deploy the flashloan borrower contract builder.deploy(None, None).await.unwrap();

// Execute the flashloan and grab the transaction receipt let optionaltxreceipt = builder.execute().await.unwrap(); let txreceipt = optionaltx_receipt.unwrap();

Builder Pattern

,ignore
use std::{str::FromStr, sync::Arc};
use flashloan_rs::prelude::*;
use ethers::prelude::*;

// Create a web3 provider let client = Provider::<Http>::try_from("https://eth-mainnet.g.alchemy.com/v2/your-api-key").unwrap(); let arc_client = Arc::new(client);

// Config let walletaddress = Address::fromstr("YOUR_ADDRESS").unwrap(); let lender = Address::fromstr("LENDERADDRESS").unwrap(); let tokentoflashloan = Address::fromstr("TOKENADDRESSTOFLASHLOAN").unwrap(); let amounttoflashloan = U256::fromdecstr("1000000000000000000").unwrap();

// Create a flashloan builder let mut builder = FlashloanBuilder::new(arc_client, 1, None, None, None, None, None);

// Set values using the builder pattern builder.withowner(walletaddress).withlender(lender).withtoken(tokentoflashloan).withamount(amountto_flashloan);

// ...

Blueprint

flashloan-rs
โ”œโ”€ contracts
โ”‚  โ”œโ”€ interfaces
โ”‚  โ”‚  โ”œโ”€ IERC20.sol โ€” ERC20 interface
โ”‚  โ”‚  โ”œโ”€ IERC3156FlashBorrower.sol โ€” Flashloan borrower interface
|  |  โ””โ”€ IERC3156FlashLender.sol โ€” Flashloan lender interface
โ”‚  โ”œโ”€ FlashBorrower.huff โ€” A https://github.com/huff-language Flashloan Receiver Contract Implementation
โ”‚  โ””โ”€ FlashBorrower.sol โ€” An Extensible Flashloan Receiver Contract
โ”œโ”€ examples
โ”‚  โ”œโ”€ custom_borrower.rs โ€” Flashloan-rs usage with a custom borrower contract
โ”‚  โ””โ”€ pure_arb.rs โ€” Executing a pure arbitrage with flashloan-rs
โ”œโ”€ lib โ€” Foundry Libraries
โ”œโ”€ src
โ”‚  โ”œโ”€ builder.rs โ€” The primary rust FlashloanBuilder library
โ”‚  โ”œโ”€ contract.rs โ€” Abi Generated FlashBorrower Contract
โ”‚  โ”œโ”€ errors.rs โ€” Custom errors for flashloan-rs
โ”‚  โ””โ”€ lib.rs โ€” Module Exports
โ”œโ”€ tests
โ”‚  โ”œโ”€ contracts
โ”‚  โ”‚  โ””โ”€ FlashBorrower.t.sol โ€” FlashBorrower.sol test suite
โ”‚  โ””โ”€ crate
|     โ””โ”€ builder.rs โ€” Unit tests for flashloan-rs
โ”œโ”€ foundry.toml โ€” Foundry Config
โ””โ”€ Cargo.toml โ€” The flashloan-rs Cargo Manifest

License

MIT

Acknowledgements

A few very notable repositories that were used as reference:

๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท whitenois3/flashloan-rs ยท Updated daily from GitHub