flashloan-rs •

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:
[]
= "0.2.3"
Usage
Flashloan-rs is built to be extremely simple to use.
Quick Construction
use ;
use *;
use *;
// Create a web3 provider
let client = try_from.unwrap;
let arc_client = new;
// Config
let wallet_address = from_str.unwrap;
let lender = from_str.unwrap;
let token_to_flashloan = from_str.unwrap;
let amount_to_flashloan = U256from_dec_str.unwrap;
// Create a flashloan builder
// Alternatively, these parameters can be set using the builder pattern (see the next example)
let mut builder = new;
// Deploy the flashloan borrower contract
builder.deploy.await.unwrap;
// Execute the flashloan and grab the transaction receipt
let optional_tx_receipt = builder.execute.await.unwrap;
let tx_receipt = optional_tx_receipt.unwrap;
Builder Pattern
use ;
use *;
use *;
// Create a web3 provider
let client = try_from.unwrap;
let arc_client = new;
// Config
let wallet_address = from_str.unwrap;
let lender = from_str.unwrap;
let token_to_flashloan = from_str.unwrap;
let amount_to_flashloan = U256from_dec_str.unwrap;
// Create a flashloan builder
let mut builder = new;
// Set values using the builder pattern
builder.with_owner.with_lender.with_token.with_amount;
// ...
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
Acknowledgements
A few very notable repositories that were used as reference: