5个版本

0.2.3 2022年10月7日
0.2.2 2022年10月7日
0.2.1 2022年10月7日
0.2.0 2022年10月7日
0.1.0 2022年10月7日

#3 in #arbitrage

MIT 许可证

4.5MB
37K SLoC

Solidity 37K SLoC // 0.3% comments Rust 169 SLoC // 0.1% comments Shell 40 SLoC // 0.4% comments

flashloan-rs • ci license solidity Crates.io

带有可扩展Rust SDK的最小化Flashloan借款合约。

入门指南

Flashloan-rs 已发布到crates.io,名称为 flashloan-rs

要在Rust项目中使用此包,运行以下cargo add命令:cargo add flashloan-rs

或者,将以下内容添加到您的Cargo.toml中

[dependencies]
flashloan-rs = "0.2.3"

使用方法

Flashloan-rs 设计得非常简单易用。

快速构建

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 wallet_address = Address::from_str("YOUR_ADDRESS").unwrap();
let lender = Address::from_str("LENDER_ADDRESS").unwrap();
let token_to_flashloan = Address::from_str("TOKEN_ADDRESS_TO_FLASHLOAN").unwrap();
let amount_to_flashloan = U256::from_dec_str("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(token_to_flashloan),   // token address to flashloan
    Some(amount_to_flashloan),  // 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 optional_tx_receipt = builder.execute().await.unwrap();
let tx_receipt = optional_tx_receipt.unwrap();

构建器模式

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 wallet_address = Address::from_str("YOUR_ADDRESS").unwrap();
let lender = Address::from_str("LENDER_ADDRESS").unwrap();
let token_to_flashloan = Address::from_str("TOKEN_ADDRESS_TO_FLASHLOAN").unwrap();
let amount_to_flashloan = U256::from_dec_str("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.with_owner(wallet_address).with_lender(lender).with_token(token_to_flashloan).with_amount(amount_to_flashloan);

// ...

蓝图

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

许可证

MIT

致谢

一些非常有名的仓库被用作参考

依赖项

~20–37MB
~549K SLoC