Skip to content

About

Kodiak V3 flash loans for claiming tokens from the Infared `BribeCollector`

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

FlashCollector: Flash Loan-Based Token Claiming and Swapping

FlashCollector is a Solidity smart contract designed to leverage Kodiak V3 flash loans for claiming tokens from the Infared BribeCollector contract and swapping them for WBERA (Wrapped BERA) on decentralized exchanges (DEXs) like Kodiak V3 and Beraswap. The contract streamlines the process of token claiming and swapping, repaying the flash loan, and keeping any remaining WBERA as profit—all in a single transaction.

This project is experimental and open-source, inviting developers and users to explore, use, and contribute to its development.

Table of Contents

Introduction

The FlashCollector contract enables users to:

  • Borrow WBERA via Kodiak V3 flash loans without requiring upfront capital.
  • Use the borrowed WBERA to claim tokens from the Infared BribeCollector contract.
  • Swap the claimed tokens for WBERA or HONEY on supported DEXs (Kodiak V3 and Beraswap).
  • Repay the flash loan and retain any leftover WBERA as profit.

This project is ideal for developers and traders looking to automate token claiming and arbitrage strategies efficiently.

Features

  • Flash Loan Integration: Borrows WBERA from Kodiak V3 pools to fund token claiming.
  • Token Claiming: Interacts with Infared BribeCollector contract to claim multiple tokens in one go.
  • Flexible Swapping: Supports token swaps on:
    • Kodiak V3: With fee tiers of 0.3%, 0.05%, 0.01%, and 1%.
    • Beraswap: Using specific pool IDs.
  • Profit Maximization: Automatically calculates and sends profits in WBERA to the caller.
  • Configurable Pools: Allows customization of swap pools and parameters per token.

Architecture

The FlashCollector contract operates as follows:

  • Initiate Flash Loan: The user calls the initFlash function, passing parameters for token claiming and swapping.
  • Flash Loan Callback: In the uniswapV3FlashCallback function:
    • Approves the Infared BribeCollector contract to spend the borrowed WBERA.
    • Claims the specified tokens from the BribeCollector contract.
    • Swaps each claimed token for WBERA or HONEY on the configured DEX.
    • If HONEY is received, swaps it for WBERA.
    • Repays the flash loan (principal + fees).
    • Transfers any remaining WBERA to the caller as profit.

External Dependencies

  • Kodiak V3: Provides flash loans and handles token swaps with configurable fee tiers.
  • Beraswap: Facilitates swaps using predefined pool IDs.
  • BribeCollector Contract: Source of the tokens to be claimed.

Installation

To set up the project locally:

  1. Install Foundry: Follow the Foundry installation guide.

  2. Clone the Repository:

    git clone https://github.com/infrared-dao/flash-collector.git
    cd flash-collector
  3. Install Dependencies:

    forge install
  4. Test:

    forge test

Usage

Deploying the Contract

  1. Compile the Contract:
    forge build
  2. Deploy the Contract: Set PRIVATE_KEY in .env, then use the included deployment script:
    chmod +x /shell/*.sh
    ./shell/deploy.sh

Interacting with the Contract

Prepare FlashParams:

  • feeTokens: List of tokens to claim.
  • feeAmounts: Amounts to claim for each token.
  • swapPools: Array of PoolIdentifier structs defining swap configurations.

Run flash claim when conditions are correct:

```bash
./shell/run.sh
```

Configuration

PoolIdentifier Struct

For each token, configure a PoolIdentifier:

  • poolType:
    • 0: Kodiak V3.
    • 1: Balancer.
  • useHoney:
    • true: Swap to HONEY.
    • false: Swap to WBERA.
  • poolData:
    • Kodiak V3: Fee tier (e.g., abi.encode(3000) for 0.3%).
    • Balancer: Pool ID (e.g., abi.encode(poolId)).

Examples:

  • Kodiak V3 (0.3% fee, to WBERA):
    PoolIdentifier({poolType: 0, useHoney: false, poolData: abi.encode(3000)})
  • Balancer (to HONEY):
    PoolIdentifier({poolType: 1, useHoney: true, poolData: abi.encode(poolId)})

Contributing

We’d love your help! To contribute:

  1. Fork the Repository.
  2. Create a Branch:
    git checkout -b feature/your-feature
  3. Commit Changes:
    git commit -m "Describe your changes"
  4. Push to Your Fork:
    git push origin feature/your-feature
  5. Submit a Pull Request.

Please include tests and follow the project’s coding style.

License

This project is released under the MIT License.

FAQ

Why use flash loans?

Flash loans eliminate the need for upfront capital, enabling efficient token claiming and swapping in one transaction.

How is profitability ensured?

The contract estimates swap outputs and proceeds only if profits exceed flash loan fees, though market conditions may affect results.

What are the risks?

  • Slippage in swaps.
  • Failures in external contracts (e.g., auction or DEXs).
  • Reentrancy vulnerabilities if not secured.

About

Kodiak V3 flash loans for claiming tokens from the Infared `BribeCollector`

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages